java字符串list排序

@Test
	public void test2() {
		List list = new ArrayList();
		list.add("abce");
		list.add("a");
		list.add("110");
		list.add("1");
		list.add("abcd");
		Collections.sort(list, (a, b) -> {
			if (a.equals(b)) return 0;
			if (a.length() > b.length()) {
				return 1;
			} else if (a.length() < b.length()) {
				return -1;
			} else {
				return a.compareTo(b);
			}
		});
		for (String str : list) {
			System.out.println(str);
		}
	}

 

你可能感兴趣的:(java字符串list排序)