0

I want to sort a few strings:

 RANDOM.XY
 AAA.BBB.CC
 AAA.BBB
 RANDOM.XY.Z
 AAA.BBB.CC.D

The sorted order should be:

 AAA.BBB
 AAA.BBB.CC
 AAA.BBB.CC.D
 RANDOM.XY
 RANDOM.XY.Z

I put them in an ArrayList list, and used a built-in sort method:

 Collections.sort(list);

However, what I get from the sorting is:

 AAA.BBB.CC.D
 AAA.BBB.CC
 AAA.BBB
 RANDOM.XY.Z
 RANDOM.XY

How should I go about this?

4

1 Answer 1

2

You can create your custom class that contains the original string and a string that doesn't contain the dots. You then can implement the Comparator interface and compare the strings that doesn't contain the dots.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.