String str = "asdfasdfafk asd234asda";
Map<Character, Integer> charMap = new HashMap<Character, Integer>();
char[] arr = str.toCharArray();
for (char value: arr) {
if (Character.isAlphabetic(value)) {
if (charMap.containsKey(value)) {
charMap.put(value, charMap.get(value) + 1);
} else {
charMap.put(value, 1);
}
}
}
System.out.println(charMap);
Friday, December 21, 2018
Java - Duplicate chars in a String
Subscribe to:
Post Comments (Atom)
TestNG - Can i use the 2 different data providers to same @test methods in TestNG?
public Object [][] dp1 () { return new Object [][] { new Object [] { "a" , "b" }, new Obje...
-
public Object [][] dp1 () { return new Object [][] { new Object [] { "a" , "b" }, new Obje...
-
package programs; import java.util.Scanner; public class ReverseNumber { public void reverseNumber(){ Scanner scn = new ...
-
package programs; import java.util.HashMap; public class CountNumberInArray { public static void main(String[] args) { int[] a =...
No comments:
Post a Comment