How to sort and get highest value from Java Object/ArrayList -


this question has answer here:

i have arraylist student objects (name, mark in math, mark in physics). how can sort arraylist , edit first highest number/s, second highest third , on. example have object value below:

arraylist<> allstudents = new arraylist(); allstudents.add(new student("a", 80, 94) ); allstudents.add(new student("b", 98, 91) ); allstudents.add(new student("f", 70, 84) ); allstudents.add(new student("c", 98, 92) ); allstudents.add(new student("h", 99, 93) ); 

i student highest number, got h. edit object like: "h", 97, 90 , save arralist. again 2nd highest here have students "b" , "c", can see same number in math in physics c has highest number edit "c", 96, 90 , save arraylist , on. here student edited, not fetch them edit , save thr , on. if please me! in advance

you need create comparator can anonymous or class , in student method mark can use inside comparator compare marks sorting

example:

arraylist<student> allstudents = new arraylist();         allstudents.add(new student("a", 80, 94));         allstudents.add(new student("b", 98, 91));         allstudents.add(new student("f", 70, 84));         allstudents.add(new student("c", 98, 92));         allstudents.add(new student("h", 99, 93));          collections.sort(allstudents, new comparator<student>() {              public int compare(student s, student s2) {                 return s.getmark() - s2.getmark();             }         }); 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -