Created
January 14, 2013 22:54
-
-
Save jmgrosen/4534321 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.ArrayList; | |
| import java.util.Random; | |
| /** | |
| * Created with IntelliJ IDEA. | |
| * User: john | |
| * Date: 1/14/13 | |
| * Time: 10:29 AM | |
| * To change this template use File | Settings | File Templates. | |
| */ | |
| public class Foo { | |
| static Random random = new Random(); | |
| static int getNum() { | |
| return random.nextInt(); | |
| } | |
| public static void main(String[] args) { | |
| ArrayList<Shape> shapes = new ArrayList<Shape>(); | |
| shapes.add(new Shape("red")); | |
| shapes.add(new Shape("blue")); | |
| shapes.add(new Shape("green")); | |
| shapes.forEach((Shape s) -> s.setNum(getNum())); | |
| shapes.forEach(Foo::printShape); | |
| shapes.sort((Shape s1, Shape s2) -> { | |
| if (s1.getNum() > s2.getNum()) { | |
| return 1; | |
| } else if (s1.getNum() < s2.getNum()) { | |
| return -1; | |
| } else { | |
| return 0; | |
| } | |
| }); | |
| shapes.forEach(Foo::printShape); | |
| } | |
| public static void printShape(Shape s) { | |
| System.out.println(s.getColor() + ", " + s.getNum()); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment