How to Check the Equality of TWO STRING IN JAVA

String is the important data type in programming. In Java there are many functions of string which are use to manipulate the records which exist in string. The string will be equal if and only if they have same length and character.

Source Code


package com.stringmatch.www;
import java.util.Scanner;

public class Compare_string {

    
    public static void main(String[] args) {
      String a ="";
      String b ="";
      Scanner input = new Scanner (System.in);
      System.out.println(" Enter Your Sentence ");
      a = input.nextLine();
      System.out.println(" Enter Your Sentence  ");
      b = input.nextLine();
     if ( a.equals(b))
     {
         System.out.println(" Sentence Match ");
     }
        else
     {
         System.out.println(" Sentence Does not Match ");
     }
    
    }
    }

Output of the Program


Java String Programming
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