The method compare(long, long) is undefined for the type Long
comparator, java
Solution
This method exists since Java 7. You're probably using a Java 6 or even older version of Java. In these previous versions, you can simply use
Long.valueOf(l1).compareTo(Long.valueOf(l2));
The javadoc is your friend. Read it.
Problem
I need to make a Comparator to sort my List of objects by one of its variables which is of `long` type. ``` public class ParticipantIndexComparator implements Comparator<Integer> { final List<Participant> participants; public ParticipantIndexComparator(ArrayList<Integer> numbersToSort) { participants=new ArrayList<Participant>(); for (int i=0;i<numbersToSort.size();i++) { participants.add(i,competition.participant.get(numbersToSort.get(i))); participants.get(i).comparator=numbersToSort.get(i);} } @Override public int compare(Integer i1, Integer i2) { long l1 = participants.get(i1).kpTime.get(kpSelected); long l2 = participants.get(i2).kpTime.get(kpSelected); return Long.compare(l1, l2); } } ``` But `return Long.compare(l1, l2);` is invalid - "The method compare(long, long) is undefined for the type Long". Seems like I'm doing it the wrong way.