How do I create a custom order to sort Java String phone numbers?… here is a solution to the problem.
How do I create a custom order to sort Java String phone numbers?
I
have a list of Java String phone numbers and I need to categorize them based on their carrier, such as “013…” and “017…”, which are all the same carrier number.
List<String> phoneNumberList = new ArrayList<String>();
phoneNumberList.add("01313445566");
phoneNumberList.add("01414556677");
phoneNumberList.add("01515667788");
phoneNumberList.add("01616778899");
phoneNumberList.add("01717889900");
phoneNumberList.add("01818990011");
phoneNumberList.add("01919001122");
When I print them, they look like –
01313445566
01414556677
01515667788
01616778899
01717889900
01818990011
01919001122
But I want to print them using a custom order –
01313445566,
01717889900,
01414556677,
01919001122,
01515667788,
01616778899,
01818990011
How do I create custom orders to sort them according to my requirements?