Compare Two String in Java

This is the simple java program for beginners about string. The program compare two strings and generate the results which is greater string.


Source Code 

import java.util.Scanner;

public class LinkedList
{
   public static voidmain(String args[])
   {
      Stringf_String;
      String s_String;
      Scanner in = new Scanner(System.in);

      System.out.println("Enter First String :");
      f_String = in.nextLine();

      System.out.println("Enter Second String :");
      s_String = in.nextLine();

      if ( f_String.compareTo(s_String) > 0 )
      {
         System.out.println("First String Less Than Second ! ");
      }
      else if ( f_String.compareTo(s_String) < 0 )
      {
          System.out.println("First String Greater Than Second ! ");
      }
      else
      {
         System.out.println("Strings Equal !");
      }
  
   }

}

Output of the Program 

Java String Functions
Compare Strings

Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment