java collection sort on the bases of another collection -


i have been asked question in interview:

class student{   int rollno;   string name;   list<mark> marks; }  class mark{   string subject;   int mark; } 

how student collection student has secured third highest marks?

since in collection can call collections.sort custom comparator so:

   collections.sort(studentlist, new comparator<student>() {        @override        public int compare(student a, student b) {            double mark_a = collections.max(a.marks);            double mark_b = collections.max(b.marks);            return double.compare(mark_a, mark_b);        }    }); 

then can return third student. (you may need change calculation method mark_a , mark_b depending on "highest marks" means... may want average)


Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -