• Register
140 points

I am going to explain the basics of JAVA relatable with strings and its advantages and disadvantages. This article mainly focuses on strings implies with the basics of any programming language.

What is String

A string represents a text rather than numbers. It consists of characters or as a whole being included with spaces and numerals too. These strings are mainly included between double-quotes ( “  “ ) or either single-quotes ( ‘  ‘ ) which makes it easier to recognize.  

Examples of Strings

String string1 = "Hello";

// Hello is a String with its own data type

String string2 = " New String " ;

// New String is also a string with spaces included in it.

String string3 = " I have completed 3 articles on JAVA ";

//  I have completed 3 articles on JAVA is also a string which is included with both numbers, spaces.

Relational/Comparision Operator

These comparison operators are used to perform operations on its variables. While the comparison variables compare two variables. Types of operators used are
  1. Equal to ( == )
  2. Not equal ( != )
  3. Greater than ( > )
  4. Less than ( < )
  5. Greater than or equal to ( >= )
  6. Less than or equal to (>= )
Apart from these, the equals() method is used to compare strings and returns the boolean value. equals() method is used to check the nature of objects which refers to not equal operator while the equal to ( == )  used to just compare lexicographically.


  • To represent or to find a string that is not equal to the other is explained by using not equal operator(!=). We can compare two strings by using the (!=)  operator.  
  • Another method to say that the string does not equal is by using equals() method. Refer to the below example programs to know about the operation on strings.


Program 1

public class notEqual 


public static void main (String args[]) 


String s1="Article ";

String s2="Kodlogs"










Program 2

String Str1 = "Kodlogs";

String Str2 = "Kodlogs";

System.out.println(myStr1.equals(myStr2)); // Returns true because they are equal


Output for Program 1

Output for Program 2



140 points