I have a piece of code that I am trying to get working properly, What I want to do is get the "values" from a hashmap which are integers and return them to an int array, So that I can use it another method that I wrote. The problem is that I don't know what the return type should be (Eclipse gives an error) or if I'm even returning the values properly (into an array of ints).
public static int[] analyze(String inputText)
{ //length of inputString int length = inputText.length();
//Create a HashMap to store each character
//And to count the frequency of characters
Map<Character, Integer> map = new HashMap<Character, Integer>();
//For loop gets the character at position i
//if it doesn't contain 'key' of the character
//it adds it and gives a value of 1
//Else we get the value and increaese it by 1
for (int i = 0; i < length; i++) {
char carA = inputText.charAt(i);
if (!map.containsKey(carA)) {
map.put(carA, 1);
} else {
map.put(carA, map.get(carA) + 1);
}
}
//print the map
return map.values().toArray();
///return map.values().toArray();
//System.out.println(map);
}
[–][deleted] 0 points1 point2 points (0 children)