Answers for "count in java"

2

counting the number of characters in a string java

public static void main(String[] args) {
		int wordCount = 0;
		String word = "hill";
		for (char letter = 'a'; letter <= 'z'; letter++) {
			for (int i = 0; i < word.length(); i++) {
				if (word.charAt(i) == letter) {
					wordCount++;
				}
			}
			if (wordCount > 0) {
				System.out.println(letter + "=" + wordCount);
				wordCount = 0;
			}
		}
	}
Posted by: Guest on January-23-2020
1

counter in java

HashMap<String, MutableInteger> efficientCounter = new HashMap<String, MutableInteger>();
 
for (String a : sArr) {
	MutableInteger initValue = new MutableInteger(1);
	MutableInteger oldValue = efficientCounter.put(a, initValue);
 
	if(oldValue != null){
		initValue.set(oldValue.get() + 1);
	}
}
Posted by: Guest on August-01-2020
0

java count

public static void main(String[] args) 
    { 
  
        // creating a list of Integers 
        List<Integer> list = Arrays.asList(0, 2, 4, 6, 
                                           8, 10, 12); 
  
        // Using count() to count the number 
        // of elements in the stream and 
        // storing the result in a variable. 
        long total = list.stream().count(); 
  
        // Displaying the number of elements 
        System.out.println(total); 
    }
Posted by: Guest on February-23-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language