Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Map - counting with map

// counting how many letters int the string
String s = "alma mater";
Map<Character, Integer> countOfLetters = new HashMap<>();
for (char c: s.toCharArray()) {
    if (countOfLetters.containsKey(c)) {
        countOfLetters.put(c, countOfLetters.get(c) + 1);
    }
    else {
        countOfLetters.put(c, 1);
    }
}
System.out.println(countOfLetters); // { =1, a=3, r=1, t=1, e=1, l=1, m=2}
int numberOfM = countOfLetters.get('m'); // 2
Comment

PREVIOUS NEXT
Code Example
Java :: How to send saved CSV file via email 
Java :: jdsu software download 
Java :: array 2 
Java :: java can an object be used as a key 
Java :: why the fuck java suck 
Java :: spring aop xml definition 
Java :: JAVA Declaration Statements 
Java :: Algorithms - sum 
Java :: java and python begineers mcq with answers 
Java :: jkora 
Java :: print all prime no java 
Java :: Marging ViewPager 
Java :: programme javascrip mineur et majaur 
Java :: sha-1 key generator 
Java :: how to make bidirectional fromated binding 
Java :: remove character stringbuffer 
Java :: spigot bukkit self cancelling task timer example repeat times 
Java :: Get Subarray from Array 
Java :: cfgbcfdxv 
Java :: convert boolean to Boolean class 
Java :: where do you use overriding in framework 
Java :: how-to-use-volley-string-request-in-android 
Java :: how get most comon element in map java 
Java :: fly dfguyghj: Javascript 
Java :: write arraylist to outputstream java byte file 
Java :: java file and stream 
Java :: Get Max Value Element From List With Objects 
Java :: return vs break 
Java :: lmethod java 
Java :: komplettes array ausgeben java 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =