Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.Comparator;
- import java.util.List;
- final class Entity {
- private final int posX;
- public Entity(int x) {
- posX = x;
- }
- public int getX() { return posX; }
- }
- public final class Start
- {
- public static void main(String[] args)
- {
- final List<Entity> list = Arrays.asList(
- new Entity(20),
- new Entity(50),
- new Entity(10)
- );
- // Als Lambda
- list.sort(Comparator.comparing(Entity::getX).reversed());
- // Sortiert
- list.forEach(e -> { System.out.println(e.getX()); });
- }
- }
Add Comment
Please, Sign In to add comment