集合遍历
public static void main(String[] args) {
ArrayList<String> strings = new ArrayList<>();
strings.add("1");
strings.add("2");
strings.add("3");
// strings.forEach(new Consumer() {
// @Override
// public void accept(Object o) {
// System.out.println("o:" + o);
// }
// });
strings.forEach((s) -> {
System.out.println(s);
});
}
集合排序
public static void main(String[] args) {
ArrayList<UserEntity> userlists = new ArrayList<>();
userlists.add(new UserEntity("mayikt", 22));
userlists.add(new UserEntity("xiaomin", 18));
userlists.add(new UserEntity("xiaoha", 36));
userlists.sort(new Comparator<UserEntity>() {
@Override
public int compare(UserEntity o1, UserEntity o2) {
return o1.getAge() - o2.getAge();
}
});
userlists.sort((o1, o2) -> o1.getAge() - o2.getAge());
}