Guest User

Untitled

a guest
Aug 17th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Arrays;
  2. import java.util.Comparator;
  3. import java.util.List;
  4.  
  5. final class Entity {
  6.     private final int posX;
  7.    
  8.     public Entity(int x) {
  9.         posX = x;
  10.     }
  11.    
  12.     public int getX() { return posX; }
  13. }
  14.  
  15. public final class Start
  16. {  
  17.     public static void main(String[] args)
  18.     {
  19.         final List<Entity> list = Arrays.asList(
  20.             new Entity(20),
  21.             new Entity(50),
  22.             new Entity(10)
  23.         );
  24.    
  25.         // Als Lambda
  26.         list.sort(Comparator.comparing(Entity::getX).reversed());
  27.        
  28.         // Sortiert
  29.         list.forEach(e -> { System.out.println(e.getX()); });
  30.     }
  31.    
  32. }
Add Comment
Please, Sign In to add comment