Created
October 26, 2016 04:04
-
-
Save DickyT/44816fd11bc27e36b2593b16a418286b to your computer and use it in GitHub Desktop.
This file contains 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.Collections; | |
import java.util.Comparator; | |
/** | |
* Created by KanzakiMirai on 10/26/16. | |
*/ | |
public class Test { | |
public static void main(String[] args) { | |
Demo tmp = new Demo(); | |
tmp.main(); | |
} | |
} | |
class Demo { | |
ArrayList<Hero> arrayList = new ArrayList<>(); | |
void main() { | |
this.arrayList.add(new Hero("Reaper", 250)); | |
this.arrayList.add(new Hero("Mei", 250)); | |
this.arrayList.add(new Hero("Mercy", 200)); | |
this.arrayList.add(new Hero("D.VA", 600)); | |
this.arrayList.add(new Hero("Roadhog", 600)); | |
System.out.println("arrayList = " + arrayList); | |
Comparator<Hero> comparator = (o1, o2) -> o2.health - o1.health; | |
Collections.sort(this.arrayList, comparator); | |
System.out.println("this.arrayList = " + this.arrayList); | |
} | |
} | |
class Hero { | |
public String name; | |
public Integer health; | |
Hero(String name, Integer health) { | |
this.name = name; | |
this.health = health; | |
} | |
@Override | |
public String toString() { | |
return String.format("name: %s, health: %d", this.name, this.health); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment