Monday 28 March 2016

Java Tutorial : Java String [compareTo(String anotherString) method]


Click here to watch in Youtube :
https://www.youtube.com/watch?v=E7qw-HfJitU&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
Java Tutorial : Java String [compareTo(String anotherString) method] 
CompareToDemo.java
/*
 * public int compareTo(String anotherString)
 *
 * Parameters:
 * ----------
 * anotherString - the String to be compared.
 *
 * Returns:
 * -------
 * the value 0 if the argument string is equal to
 * this string;
 *
 * a value less than 0 if this string
 * is lexicographically less than the string
 * argument;
 *
 * a value greater than 0 if this
 * string is lexicographically greater than the
 * string argument.
 */

public class CompareToDemo
{
    public static void main(String[] args)
    {

        int result = "Welcome".compareTo("Welcome");
        System.out.println("\"Welcome\".compareTo(\"Welcome\") = "
                + result);

        result = "Hello".compareTo("Welcome");
        System.out.println("\"Hello\".compareTo(\"Welcome\") = "
                + result);

        result = "Welcome".compareTo("Apple");
        System.out.println("\"Welcome\".compareTo(\"Apple\") = "
                + result);

    }
}
Output
"Welcome".compareTo("Welcome") = 0
"Hello".compareTo("Welcome") = -15
"Welcome".compareTo("Apple") = 22
Click the below link to download the code:
https://sites.google.com/site/javaee4321/java/StringDemo_compareTo_App.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/StringDemo_compareTo_App

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/f763f2167329fa6e35d47d9d3a5195613480d629/BasicJava/StringDemo_compareTo_App/?at=master

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • No comments:

    Post a Comment