Delete a single record of each type based on the arrayist

advertisements

I have a ArrayList of String array. String array looks something like below

["Type-A","Date","Expert"]
["Type-A","Date","07 Expert"]
["Type-A","Date","10 Expert"]
["Type-B","Date","Expert"]
["Type-B","Date","10 Expert"]
["Type-C","Date","07 Expert"]
["Type-C","Date","10 Expert"]

Consider arraylist have above string arrays. I want to take out unique type from each type from arraylist on thee basis of expertise level. If we cosider above list then I want Type-A with level as Expert and Type-B with level as Expert and Type-C with level as Expert10 as in hierarchy Expert is at top and Expert10 and Expert07 are lower to it.

The structure is like I have arraylist which contains string array. Each String array record has Type and expertise level. Arraylist can have multiple records of same Type with different expertise level. I want record of each Type but with highest expertise level. I have a list if different expertise level. Now my confusion is how to use that expertise level list to take out or make another arraylist with single record of each type with highest expertise level.

List of expertise level.

Expert
10 Expert
07 Expert
Professional
Systems
10 System
07 System


Just loop it and find out, using a map to store current max expert item for each type during looping:

private boolean isMoreExpert(String expertPicked, String expertToCompare){
    //TODO: return true is expertPicked is lower expert than expertToCompare, false otherwise
    return false;
}

private List<String[]> mapToList<Map<String[]> map>{
    //TODO: iterate the map and store items to a list
    return null;
}
private List<String[]> getMostExpertListOfEachType(List<String[]> items){
    Map<String, String[]> tempRecord = new HashMap<>();
    for(String[] item in items){
        //assume first item is the type
        String[] current = tempRecord.get(item[0]);
        //assume the third item is the expert
        if(current != null ){
             if(isMoreExpert(current[2], item[2])){tempRecord.put(item[0], item);}
        }else{
            tempRecord.put(item[0], item);
        }
    }
    return mapToList(tempRecord);
}

Have not tested the code yet:)