Java

How to Compare Two Strings in Java Without Using Equals1 min read

In this java example we will learn that given two strings, find out if they are equal or not without using any built-in function (without using equals() function in java).

Example Java Code:




Output:

 

Approach:

  • If any of the string is null, return false.
  • If lengths of both strings are not matching, return false.
  • Check if all the characters of both strings are matching, if not return false.
  • If all the steps above got executed without returning false then return true.

 

Leave a Comment