Mega Code Archive

 
Categories / Android / Date Type
 

Count char in a string

import java.util.Random; class Main {     public static int count(String text, char c) {         if (text == null) {             return 0;         }         int result = 0;         for (char it : text.toCharArray()) {             if (it == c) {                 ++result;             }         }         return result;     } }