Skip to content

Ignoring whitespaces #12

Description

@krasa

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("---------");
	}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions