natorder icon indicating copy to clipboard operation
natorder copied to clipboard

Ignoring whitespaces

Open krasa opened this issue 4 years ago • 0 comments

Ignoring whitespaces does not really produce a nice result:

The A
The X
The a
Theme
The x

If anything, it would be better to ignore them only between digits, to be able to sort this:

1
1 000 000
10
10 000
10 000 000
100
100 000
1000
	public static void whitespace() {
		List<String> list = new ArrayList<>();
		list.add("The a");
		list.add("The x");
		list.add("Theme");
		list.add("The X");
		list.add("The A");

		Collections.sort(list, new NaturalOrderComparator());
		for (String item : list) {
			System.out.println(item);
		}
		System.out.println("---------");
	}

	public static void whitespaceInNumbers() {
		List<String> list = new ArrayList<>();
		list.add("10 000 000");
		list.add("1 000 000");
		list.add("100 000");
		list.add("10 000");
		list.add("1000");
		list.add("100");
		list.add("10");
		list.add("1");

		Collections.sort(list, new NaturalOrderComparator());
		for (String item : list) {
			System.out.println(item);
		}
		System.out.println("---------");
	}

krasa avatar Apr 22 '20 23:04 krasa