Quantcast
Channel: How can I sort list of object based on one of the object's variables - Stack Overflow
Browsing all 5 articles
Browse latest View live

Answer by Roshan Halwai for How can I sort list of object based on one of the...

There are two ways of solving this problemImplementing compare method of comparator interface in second parameter of Collections.sort method.Ensuring your class implements Comparable interface and then...

View Article



Answer by Tobb for How can I sort list of object based on one of the object's...

Your code works just fine on my computer, the following:import java.util.ArrayList;import java.util.Collections;import java.util.Comparator;import java.util.List;public class SortFilms { public static...

View Article

Answer by Boris the Spider for How can I sort list of object based on one of...

Using the Double.compare method works fine:public static void main(String[] args) throws IOException, ClassNotFoundException { final List<Film> films = new ArrayList<>(); films.add(new...

View Article

Answer by BlackJoker for How can I sort list of object based on one of the...

Use the folowing method in Double instead:public static int compare(double d1, double d2){}or like this:class Film implements Comparable<Film>{ double rating; @Override public int compareTo(Film...

View Article

How can I sort list of object based on one of the object's variables

I need to sort an ArrayList of films best rated to worse (5 best - 1 worst). I am using Collections.sort() but the list comes out the same. what am i doing wrongfilms.add(new...

View Article

Browsing all 5 articles
Browse latest View live




Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>