Double

四舍五入并保留小数点后两位

  1. double score = 24.2455;
  2. BigDecimal round = new BigDecimal(score).setScale(2, RoundingMode.UP);
  3. System.out.println(round.doubleValue());

Iterable

转List类型

  1. Iterable<Teacher> teacherIterable = repository.findAll();
  2. List<Teacher> teacherList = new ArrayList<>();
  3. teacherIterable.forEach(teacherList::add);

Collections


单个对象转换成List

  1. List<MyObject> = Collections.singletonList(myObject);

将列表转换成不可修改的容器

  1. Collections.unmodifiableList(items)