Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

count occurrences of character in string java 8

String someString = "elephant";
long count = someString.chars().filter(ch -> ch == 'e').count();
assertEquals(2, count);
 
long count2 = someString.codePoints().filter(ch -> ch == 'e').count();
assertEquals(2, count2);
Comment

count the number of occurrences of a character in a string java

String line = "apples.oranges.bananas";
int count = line.length() - line.replace(".", "").length();
System.out.println(count);//displays 2
Comment

PREVIOUS NEXT
Code Example
Java :: fill two dimensional array column by column java 
Java :: fill two dimensional array columns by columns java 
Java :: arraylist syntax in java 
Java :: List into string java 
Java :: how to remove null values collections 
Java :: gridlayout android studio 
Java :: Java Create ArrayList in Java 
Java :: java regex 
Java :: java mongodb find with multiple conditions 
Java :: intent android 
Java :: get thumbnail from video in android 
Java :: get length of a string java 
Java :: Java How to use Set? 
Java :: creating a directory using java 
Java :: exception in thread "main" java.lang.indexoutofboundsexception: index 1 out of bounds for length 1 
Java :: dequeue in java 
Java :: java throw keyword 
Java :: java wait(timeout) 
Java :: Java Writer Using FileWriter 
Java :: how to reverse a string in java without function 
Java :: java constructor overloading 
Java :: how to round double to 2 decimal places java 
Java :: how to save a string to a text file 
Java :: how to get color from a hex string in android studio 
Java :: display two dimension array java 
Java :: check if a list contains a string java 
Java :: json array get json object 
Java :: abstraction in java 
Java :: java get filename without extension 
Java :: java explicit array declaration 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =