I have read a CSV file into a ArrayList but need to use a for loop to sum all the values that have a specific name with them, then return the top strings, in this case letters, in a string array. For example,
"A", 2
"B", 3
"C", 4
"A", 1
"B", 3
I have a class which reads the csv into objects so i have getters if that is of any help.
The result would give back a String [] that would have, in order, [B, C, A] as B totals 6, C totals 4 and A totals 3. Thank you.
Code I have so far,
public ArrayList<String> getTopRooms(int n){
ArrayList<String> roomNames = new ArrayList<>();
for (int i =0; i<recordList.size();i++){
if(!roomNames.contains(recordList.get(i).getRoomName()))
roomNames.add(recordList.get(i).getRoomName());
}
recordList contains data from the csv file, in this case i am trying to get the top rooms that have been booked. all rooms have a length of time which is shown by an int so for example, kitchen would have the length of 2.
Map<String, Integer>with letter as key and count as value.