"Not equals" can be expressed with the "not" operator ! and the standard .equals.

if (a.equals(b)) // a equals b
if (!a.equals(b)) // a not equal to b
Answer from Anthony Pegram on Stack Overflow
🌐
Java Code Geeks
examples.javacodegeeks.com › home › java development › core java
Java not equal Example - Java Code Geeks
August 10, 2021 - The main difference between == and equals is that “==” is used to compare primitives while equals() method is recommended to check equality of objects. The goes for not equal. Here we show you some examples about != Java to understand better the use of this operator.
Discussions

Making Strings not Equal a user input.
You seem to try to compare String values with == or !=. This approach does not work reliably in Java as it does not actually compare the contents of the Strings. Since String is an object data type it should only be compared using .equals(). For case insensitive comparison, use .equalsIgnoreCase(). See Help on how to compare String values in the r/javahelp wiki. Your post is still visible. There is no action you need to take. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/learnjava
8
4
February 16, 2023
Java string equals string in if statement
Nor can you extend String, because ... you're not into inheritance that's ok for now). ... Then s and t actually refer to the same String object, and ‘s == t’ will return true, because for objects the double equal sign ("==") reads as "is the same object". ... Then s!=t (because you've explicitly created a new string) although s.equals(t) will return true (because the equals method checks for value equality instead of reference equality). There is a "String constant pool" in the Java ... More on teamtreehouse.com
🌐 teamtreehouse.com
2
April 2, 2019
Java. Is there a String that is not equal to itself?

This may crash or may not, depending on how the constructor of B is defined. Maybe the constructor of B sets name to a random word every time the constructor is called or maybe it's always the same.

More on reddit.com
🌐 r/learnprogramming
4
0
September 16, 2012
No .equals()?
You can use == to compare strings in C, too. Just...not how you're thinking. More on reddit.com
🌐 r/ProgrammerHumor
252
4386
January 24, 2023
🌐
iO Flood
ioflood.com › blog › java-notequals-operator
Java '!=' Operator: Use Cases for 'Not Equals' Comparisons
February 29, 2024 - The ‘!=’ operator is not only ... When comparing objects in Java, the ‘!=’ operator checks if two object references point to different objects, not their content....
🌐
Reddit
reddit.com › r/learnjava › making strings not equal a user input.
r/learnjava on Reddit: Making Strings not Equal a user input.
February 16, 2023 -

I’m writing code for a rock, paper, scissors game and I need to check the users input to make sure they input Rock, Paper, or Scissors. I know that you can use “!=“ to compare two strings and “.equals” in an if-else statement. For the most part I have the entries, as well as the comparing the two entries to see who wins, however, I’m having trouble checking to make sure their input is correct to proceed on, I’ve tried “!=“ but it automatically will default to “Wrong Choice!” (as I have that as what will output if their entry isn’t either of the options) and I can’t seem to figure it out. Any ideas on how I would do that?

Here is the code I have for it so far,

import java.util.Scanner;

public class Assignment2 { public static void main (String[]args) { String player1; String player2;

	Scanner keyboard = new Scanner(System.in);
	
	System.out.println("*****Hello! Welcome to the Rock, Paper, Scissors Program*****");
	System.out.println("Rules: This is a two player game, both players must take turns entering their choice");
	System.out.println("\tRemember, rock beats scissors, scissors beats paper, and paper beats rock!");
	
	System.out.println("Player 1: Choose rock, paper, or scissors: ");
	player1= keyboard.nextLine();
	
	if ((player1 != "Rock") || (player1 != "Paper") || (player1 != "Scissors" )) 
	{
		System.out.println("Wrong Choice!");
		player1 = keyboard.nextLine();
	}
	else 
	{
		player2 = keyboard.nextLine();
		
	}
	
	System.out.println("Player 2: Choose rock, paper, or scissors: ");
	player2=keyboard.nextLine();
	
	
	
	if (player1.equalsIgnoreCase("Rock") && player2.equalsIgnoreCase("Scissors"))
	{
		
		System.out.println("Player 1 wins!");
		
	} 
		else if (player1.equalsIgnoreCase("Scissors")&&player2.equalsIgnoreCase("Paper"))
		{
		
			System.out.println("Player 1 wins!");
		
		} 
		else if (player1.equalsIgnoreCase("Paper")&&player2.equalsIgnoreCase("Rock")) 
		{
		
			System.out.println("Player 1 wins!");
		
		} 
		else if (player1.equalsIgnoreCase(player2)) 
		{
		
			System.out.println("It's a tie!");
		
		}
	else 
	{
			System.out.println("Player 2 wins!");
		
	}
	
	
	
	keyboard.close();
	
	
	
}

}

🌐
CodeGym
codegym.cc › java blog › random › not equals in java: figuring out what’s different
Not Equals in Java: Figuring Out What’s Different
February 25, 2025 - Here’s the scoop: != isn’t munching the chips—it’s eyeballing whether they’re the same bag in Java’s messy memory. Two new String()s = two bags. Blew my mind when I first hit that snag. Now, equals()—that’s where we actually taste the chips. Want “not equals”? Just throw a !
🌐
DEU University
web.deu.edu.tr › doc › oreily › java › langref › ch04_09.htm
[Chapter 4] 4.9 Equality Comparison Operators
The equality comparison operators in Java are used for equal-to (==) and not-equal-to (!=) comparison operations.
Find elsewhere
🌐
Quora
quora.com › How-do-you-check-if-a-string-is-not-equal-to-another-string-in-Java
How to check if a string is not equal to another string in Java - Quora
Answer (1 of 4): Below is a sample code to check for not equal to: String s1 = "hello"; String s2 = "Hello"; if (s1!= null && s2!=null) { if (!s1.equals(s2)) { System.out.println("S1 And S2 Are Not Equal"); } } Please note that the equals() method is case sensitive i.e. here it will consi...
🌐
W3Schools
w3schools.com › java › java_operators.asp
Java Operators
assert abstract boolean break byte case catch char class continue default do double else enum exports extends final finally float for if implements import instanceof int interface long module native new package private protected public return requires short static super switch synchronized this throw throws transient try var void volatile while Java String Methods · charAt() codePointAt() codePointBefore() codePointCount() compareTo() compareToIgnoreCase() concat() contains() contentEquals() copyValueOf() endsWith() equals() equalsIgnoreCase() format() getBytes() getChars() hashCode() indexOf() isEmpty() join() lastIndexOf() length() matches() offsetByCodePoints() regionMatches() replace() replaceAll() replaceFirst() split() startsWith() subSequence() substring() toCharArray() toLowerCase() toString() toUpperCase() trim() valueOf() Java Math Methods ·
🌐
Coderanch
coderanch.com › t › 661872 › java › Comparing-String-Equal
Comparing a String to NOT Equal (Beginning Java forum at Coderanch)
February 9, 2016 - Knute Snortum wrote:First of all, you never need to write: Simplify the code to Next, think about what it means when this code evaluates false: my_vowels.vowels[0] evaluates to "a". So if you find yourself in the else block, the letter is not an "a". That means it could be another vowel or a consonant, you don't know.
🌐
CodeChef
codechef.com › learn › course › java › JAVANEW16 › problems › WNDHVZ16
Comparison with Not Equal (!=) in Java Conditionals in Java
Test your Learn Java knowledge with our Comparison with Not Equal (!=) in Java Conditionals practice problem. Dive into the world of java challenges at CodeChef.
🌐
Quora
quora.com › How-do-you-write-the-not-equals-sign-on-Java
How to write the not equals sign on Java - Quora
The method returns true if the strings compared are equal and false otherwise. To negate the result, just put an exclamationmark in front of the statement. String str1 = "hi"; String str...
🌐
Blogger
javahungry.blogspot.com › 2021 › 03 › not-equal-example-opposite-of-equals.html
not equal example : (opposite of .equals java) | Java Hungry
Read Also: Difference between == and equals method in Java ... !=(pronounced not equal to) is the opposite of the equality(==) operator. It will evaluate to true if the values of the two operands are different. It is a relational operator.
🌐
Housing Innovations
dev.housing.arizona.edu › home › finces › not equals string in java: a comprehensive guide to string comparison
Not Equals String in Java: A Comprehensive Guide to String Comparison - Housing Innovations
May 20, 2025 - The "not equals" operator in Java is denoted by the symbol "!=" and is used to compare the memory locations of two objects. However, when it comes to string comparison, using the "!=" operator can lead to unexpected results.
🌐
W3Schools
w3schools.com › java › ref_string_equals.asp
Java String equals() Method
Java Examples Java Videos Java ... equals() method compares two strings, and returns true if the strings are equal, and false if not....
🌐
SAP Community
community.sap.com › t5 › technology-q-a › java-checking-for-not-equal-to › qaq-p › 1930277
Java :Checking for Not equal to - SAP Community
February 12, 2007 - I need to check that If the Str1..str5 (all) each one not quals to '0000' then only proceed otherwise not ... instead of having a number of if condition convert Str1..str5 to integer and sumup. check if greater than 0. else do ur operation. ... if (( !(str1.equals("000000")) && !(str2.equals("0000000")) && !(str3.equals("000000")) && !(str4.equals("00000000"))))
🌐
Baeldung
baeldung.com › home › java › core java › difference between == and equals() in java
Difference Between == and equals() in Java | Baeldung
November 27, 2025 - Java doesn’t allow assigning or comparing null with primitive values. For object types, the equality operator performs a referential equality comparison only, ignoring the object values.
🌐
Team Treehouse
teamtreehouse.com › community › java-string-equals-string-in-if-statement
Java string equals string in if statement (Example) | Treehouse Community
April 2, 2019 - Nor can you extend String, because it's declared as final, meaning no sub-classing is allowed (if you're not into inheritance that's ok for now). ... Then s and t actually refer to the same String object, and ‘s == t’ will return true, because for objects the double equal sign ("==") reads as "is the same object". ... Then s!=t (because you've explicitly created a new string) although s.equals(t) will return true (because the equals method checks for value equality instead of reference equality). There is a "String constant pool" in the Java language.
🌐
Coderanch
coderanch.com › t › 394611 › java › strings-equal
Why are same strings not equal (Beginning Java forum at Coderanch)
If what you have said is correct that the two strings are different in physical locations then why does this program give the output equal. how is this different from the above prg and how can we be sure that the strings are pointing to same object or different other that executing the program. public class ADirtyOne05 { public static void main(String[] a) { if("String".replace('g','g') == "String".replace('g','g')) System.out.println("Equal"); else System.out.println("Not Equal"); } } "Equal" ... To understand this, you need to know two things: First, String literals are shard in the JVM, Every instance of "String" represents the same physical object; so "String" == "String" is true, while "String" == new ("String") is false. Second, the guys who wrote the Java APIs are smart enough that replace(x, x) just returns the original string, unaltered.
🌐
Blogger
javarevisited.blogspot.com › 2013 › 05 › java-mistake-3-using-instead-of-equals.html
Avoid Using "==" instead of equals() to compare Objects in Java? Example
What makes it worst is the fact ... Strings in Java, which in fact is not. In reality, the "==" operator returns true if both operands point to the same object....
🌐
Medium
medium.com › @AlexanderObregon › javas-objects-equals-method-explained-3a84c963edfa
Java’s Objects.equals() Method Explained | Medium
5 days ago - However, these approaches come with their own set of challenges. == Operator: The == operator checks for reference equality, meaning it only returns true if both references point to the same memory location.