I stuck with comparing values. Array List consists of two objects Name and Percentage.
public class DataModel {
private String name;
private String dataUsagePercent;
int color;
}
and array list is
List<DataModel> usageList;
Collections.sort(usageList, new Comparator<DataModel>(){
public int compare(DataModel d1, DataModel d2){
return (d1.getDataUsagePercent()) - Integer.parseInt(d2.getDataUsagePercent()));
}
});
Example :
dataUsagePercent values in a arraylist is 2, 10, 40, 30, 50, 60, 90, 65,55,100.
i have to compare the values of dataUsagePercent
. lowest should come at 0th position in arraylist and the top four categories
that make up the highest value of dataUsagePercent. Additionally, the six remaining values (that make up the lowest percentage of usage)
are combined into a single percentage.
Output for above values after comparing list should consists of :
2,10+30+40+50+55+60,65,90,100 means 2, 245,65,90,100
final list size should be always 5 only and name value has no impact
Edit: Missed 60. add to combined value