You’re leaving char ch set as the same character through each execution of the loop.
It should be:
ch = char_array[i];
if(charCounter.containsKey(ch)){
charCounter.put(ch, charCounter.get(ch)+1);
}
else
{
charCounter.put(ch, 1);
}
Inside the for loop.
More Related Contents:
- What are the differences between a HashMap and a Hashtable in Java?
- Initialization of an ArrayList in one line
- Why is there no SortedList in Java?
- How to convert comma-separated String to List?
- Why there is no ConcurrentHashSet against ConcurrentHashMap
- Assert equals between 2 Lists in Junit
- Java Immutable Collections
- How to copy a java.util.List into another java.util.List
- How do I keep the iteration order of a List when using Collections.toMap() on a stream?
- What is the most efficient Java Collections library? [closed]
- How to convert a Java object (bean) to key-value pairs (and vice versa)?
- How to sort alphabetically while ignoring case sensitive?
- Binding a list in @RequestParam
- Java List Sorting: Is there a way to keep a list permantly sorted automatically like TreeMap?
- What is the time complexity performance of HashSet.contains() in Java?
- Easy way to convert Iterable to Collection
- Add multiple items to an already initialized arraylist in Java
- Ordering of elements in Java HashSet
- Multiple indexes for a Java Collection – most basic solution?
- ArrayList: how does the size increase?
- Using a prepared statement and variable bind Order By in Java with JDBC driver
- Sort List of Strings with Localization
- Iterate through string array in Java
- How to flatten all items from a nested Java Collection into a single List?
- Checking if a collection is empty in Java: which is the best method?
- ArrayList vs LinkedList from memory allocation perspective
- Why Collections.sort uses merge sort instead of quicksort?
- Best way to get value from Collection by index
- How to remove common values from two array lists
- How to convert an int[] array to a List?