java check how many times a character appears in a string

java check how many times a character appears in a string

Java count character occurrences in a string:

/**
 * @author lautturi.com
 * Java example: Check how many times a character appears in a string
 */

import java.util.*;
import java.io.File;

public class Lautturi {
	public static void main(String[] args) {

		String str = "hello lautturi java world!";
		int count = (int) str.chars().filter(num -> num == 'a').count();

		System.out.println("Times:"+count);
		
	}
}
Source:ww‮al.w‬utturi.com

output:
The character a appears 3 times

Times:3
Created Time:2017-09-02 20:52:33  Author:lautturi