Question: Write a Comparator MyStringComparator that compares String objects of a particular format. Each string is of a form such as 123456, Seattle, WA, beginning with

Write a Comparator MyStringComparator that compares String objects of a particular format. Each string is of a form such as "123456, Seattle, WA", beginning with a numeric token that is followed by additional text tokens. Your job is to treat the first tokens as integers and compare them in numerical order. You cannot simply compare them by using the strings compareTo method, since it would treat the numbers as text and not as integers. For example, "276453, Helena, MT" is greater than "9847, New York, NY". You can use a Scanner to tokenize the strings while comparing them. Please write MyStringSortingClient class with has main method and has the strings in an array which will use the above comparator MyStringComparator to sort them and also print the sorted strings one in each line.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!