-1

I am trying to implement the following C# code in Java:

List<org.joda.time.DateTime> times;
...
foreach (var time in times.OrderBy(d = > d).Distinct())
...

I'm using Collections.sort() to sort times, but what's the best way to implement the Distinct() method?

sakura
  • 2,249
  • 2
  • 26
  • 39
user3352488
  • 281
  • 3
  • 15
  • Possible duplication of [Get unique values from arraylist in java](http://stackoverflow.com/questions/13429119/get-unique-values-from-arraylist-in-java) – azurefrog Apr 08 '14 at 15:13

1 Answers1

0

With new Java 8 syntax the code could look something like this:

times.stream()
    .sorted((d1, d2) -> d1.compareTo(d2)) // or just sorted() for default algorithm
    .distinct()
    .forEach(d -> System.out.println(d)); 
cit
  • 1