Google+

136. Using compareTo( ) method






compareTo( ) method is used for sorting the strings.

A string is less than another if it comes before the other in dictionary order.
A string is greater than another if it comes after the other in dictionary order.

Lets implement this on Eclipse IDE:

1. Create 'compareToDemo' class under any project as shown below:



2. Save and Run the 'compareToDemo' class file
3. Observe that the output is displayed in the console as shown below:



Download this project:

Click here to download the project containing the class file used in this post (You can download this project and import into Eclipse IDE on your machine)



Please comment below to feedback or ask questions.

Using indexOf( ) method will be explained in the next post



No comments: