Skip to content

Instantly share code, notes, and snippets.

@SergiyOsadchyy
Created June 7, 2018 10:34
Show Gist options
  • Select an option

  • Save SergiyOsadchyy/3987b03eaaf42d53273103071566d2b2 to your computer and use it in GitHub Desktop.

Select an option

Save SergiyOsadchyy/3987b03eaaf42d53273103071566d2b2 to your computer and use it in GitHub Desktop.
Java_HashMap
public class Dict {
public static void myFunc(int[] inArray) {
HashMap<Integer, Integer> dict = new HashMap<Integer, Integer>();
for (int i = 0; i < inArray.length; i++) {
if (dict.get(inArray[i]) != null) {
dict.put(inArray[i], (dict.get(inArray[i]) + 1) );
}
else {
dict.put(inArray[i], 1);
}
}
System.out.println(Arrays.asList(dict));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment