"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 - After that, we will do some examples of how we use it. Java has a rich set of operators which is used to manipulate variables. This set we can divide them into six groups : ... The operator that we will analyze in this article is a relational operator. It is symbolized "!=" or "(!a.equals(b))" and checks if the values of two operands are equal or not, in case that values are not equal then condition becomes true.
🌐
Blogger
javahungry.blogspot.com › 2021 › 03 › not-equal-example-opposite-of-equals.html
not equal example : (opposite of .equals java) | Java Hungry
To do the opposite just put an exclamation mark at the start of the statement, for example !str1.equals(str2) String str1 = "Java"; String str2 = "Hungry"; boolean notEqual = !str1.equals(str2); System.out.println( notEqual ); //true Given below is the example to compare objects
🌐
Delft Stack
delftstack.com › home › howto › java › not equals java
Not Equals in Java | Delft Stack
March 11, 2025 - In this example, we declare two integer variables, a and b. The if statement checks if a is not equal to b. Since 5 is not equal to 10, the program prints “a is not equal to b”. This simple demonstration highlights how the != operator functions ...
🌐
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...
🌐
iO Flood
ioflood.com › blog › java-notequals-operator
Java '!=' Operator: Use Cases for 'Not Equals' Comparisons
February 29, 2024 - In this example, we have two variables, x and y, with values 5 and 10 respectively. The ‘!=’ operator checks if x and y are not equal. Since 5 is not equal to 10, the condition x != y returns true, and the message ‘x and y are not equal’ ...
🌐
Educative
educative.io › answers › what-is-objectutilsnotequal-in-java
What is ObjectUtils.notEqual() in Java?
System.out.printf("ObjectUtils.notEqual(%s, %s) = %s", object1, object2, ObjectUtils.notEqual(object1, object2));
Find elsewhere
🌐
TutorialKart
tutorialkart.com › java › java-operators › java-not-equal-operator
Java Not Equal (!=) Operator
October 14, 2021 - Since, Not Equal operator returns boolean value, we can use the above expression as a condition in Conditional Statements like If-Else. In the following example, we take two integer values in x and y, and check if these two are not equal, using Not Equal Operator.
🌐
Javaprogramto
javaprogramto.com › 2020 › 11 › string-does-not-equal-java.html
Java - String not equals Examples JavaProgramTo.com
A quick guide to compare strings using != and equals() method in java. Examples on string != java and string.equals("java").
🌐
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.
🌐
W3Schools
w3schools.com › java › ref_string_equals.asp
Java String equals() Method
HTML Reference CSS Reference JavaScript Reference SQL Reference Python Reference W3.CSS Reference Bootstrap Reference PHP Reference HTML Colors Java Reference AngularJS Reference jQuery Reference · HTML Examples CSS Examples JavaScript Examples How To Examples SQL Examples Python Examples W3.CSS Examples Bootstrap Examples PHP Examples Java Examples XML Examples jQuery Examples
🌐
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();
	
	
	
}

}

🌐
Modulo
ctp.mkprog.com › en › java › not_equal_to
Java | Not equal to: != | Easy language reference
Not equal to in Java programming language is used as follows: !=. Short description of Not equal to. Shown on simple examples.
🌐
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 !
🌐
Coderanch
coderanch.com › t › 661872 › java › Comparing-String-Equal
Comparing a String to NOT Equal (Beginning Java forum at Coderanch)
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.
🌐
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 that String literal if compared with equality operation (==) or not equality operator (!=) behaves perfectly, which makes programmers think that this is the right way of comparing Strings in Java, which in fact is not. In reality, the "==" operator returns true if both operands point to the same object.
🌐
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.
🌐
Coderanch
coderanch.com › t › 394611 › java › strings-equal
Why are same strings not equal (Beginning Java forum at Coderanch)
Originally posted by Chandra Bairi: public class ADirtyOne { 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"); } } the o/p to the above is NotEqual why is this not equal
🌐
University Innovation Hub
gws.sandbox.iam.s.uw.edu › home › smartsheet
5 Ways: Equal vs. Not Equal in Java - University Innovation Hub
October 18, 2023 - The following example illustrates its usage: double pi = 3.14; double approximation = 3.15; boolean notEqual = pi != approximation; // notEqual is true · When using the equal and not equal operators, it’s crucial to understand the distinction ...