40231/count-occurance-of-string-in-an-array
Please help me find a way to solve this efficiently.
Problem statement: Find individual occurance of every character in an array.
Input:
[a,a,a,b,b,b,c,c,c,c,a]
Output:
a: 4 b: 3 c: 4
You can use hashmap to solve this, here is the function for implementing it,
Map<String,Integer> hm = new HashMap(); for(String x:array){ if(!hm.containsKey(x)){ hm.put(x,1); }else{ hm.put(x, hm.get(x)+1); } } System.out.println(hm);
Use java.util.Arrays: String res = Arrays.toString(array); System. ...READ MORE
System.arraycopy is the most efficient way, but ...READ MORE
We can use the static frequency() method. int ...READ MORE
My 'idiomatic one-liner' for this is: int count ...READ MORE
Yes; the Java Language Specification writes: In the Java ...READ MORE
We can use external libraries: org.apache.commons.lang.ArrayUtils.remove(java.lang.Object[] array, int ...READ MORE
The thing you are worried about is ...READ MORE
You can use this method: String[] strs = ...READ MORE
You can use a HashMap to serve ...READ MORE
Hi @Daisy You can use Google gson for more ...READ MORE
OR
At least 1 upper-case and 1 lower-case letter
Minimum 8 characters and Maximum 50 characters
Already have an account? Sign in.