Is there method in Java to compare the strings first letter and sort the alphabetical or I have to substring and compare them with bubble sort
Thanks

Recommended Answers

All 2 Replies

You want to sort Strings? Sure, there's library code for that. Strings are Comparable, so if you put them in an array, you can call the sort() method - see the sun reference for Arrays.

Just use string.compareToIgnoreCase("")>0. assume that the first string is the earliest alphabetical word and compare it to the next one. If the value is greater than 0, then the second string comes after the first in alphabetical. If it is less than 0, then it comes before the first string. Then put the first string after the second in the array.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.