• 当调用的方法的值为不确定数量时,如 function(String... str)
Criteria criteria = new Criteria();
List<Criteria> criteriaLists = new ArrayList<>();
for (String s : value) {
	Pattern pattern = Pattern.compile("^.*" + s + ".*$", Pattern.CASE_INSENSITIVE);
	criteriaLists.add(Criteria.where(filed).regex(pattern));
}
// 重点
criteria.orOperator(criteriaLists.stream().toArray(Criteria[]::new));
// 另一种写法
criteria.orOperator(criteriaLists.toArray(new Criteria[0]));
  • List排序
Collections.sort(fileVoList, new Comparator<FileVo>() {
	@Override
	public int compare(FileVo u1, FileVo u2) {
		int diff = u1.getIsDirectory() - u2.getIsDirectory();
		if (diff > 0) {
			return 1;
		} else if (diff < 0) {
			return -1;
		}
		return 0;
	}
});

# To Be Continued!😎

Last Updated: 11/12/2020, 5:52:46 PM