java tutorial - Java Strings contentEquals() method - java programming - learn java - java basics - java for beginners



 java strings copy value of

Learn java - java tutorial - java strings content equals - java examples - java programs

Description

Java Strings contentEquals() method — It returns true only if this string is the same string of characters which is specified in the buffer string (StringBuffer).

Syntax

The syntax of the method is:

public boolean contentEquals(StringBuffer sb)
click below button to copy the code. By - java tutorial - team

Options

Detailed information about the parameters:

  • sb - string of the buffer for comparison.

Return value

  • In Java, contentEquals () returns true only if the string is the same string as specified in the buffer string (StringBuffer), otherwise it returns false.

Sample Code

public class Test {

   public static void main(String args[]) {
      String str1 = "Welcome to Wikitechy";
      String str2 = "A site for learning programming";
      StringBuffer str4 = new StringBuffer("Welcome");
      StringBuffer str3 = new StringBuffer("Welcome to Wikitechy");
      

      boolean  result = str1.contentEquals(str3);
      System.out.println("The line \"Welcome to Wikitechy\" is equal to the buffer line \"Welcome to Wikitechy\"? \n" + result);
	  
      result = str2.contentEquals(str3);
      System.out.println("The line \"Site for learning programming\" is equal to the buffer line \"Welcome to Wikitechy\"? \n" + result);
      
      result = str1.contentEquals(str4);
      System.out.println("The line \"Welcome to Wikitechy\" is equal to the buffer line \"Welcome\"? \n" + result);
   }
}
click below button to copy the code. By - java tutorial - team

Output :

The line "Welcome to Wikitechy" is equal to the buffer line "Welcome to Wikitechy"? 
true
The line "Site for learning programming" is equal to the buffer line "Welcome to Wikitechy"? 
false
The line "Welcome to Wikitechy" is equal to the buffer line "Welcome"? 
false

Related Searches to Java Strings contentEquals() method