"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
🌐
Educative
educative.io › answers › what-is-objectutilsnotequal-in-java
What is ObjectUtils.notEqual() in Java?
The notEqual() method returns true if the objects are not equal; otherwise, it returns false.
🌐
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
🌐
Java Code Geeks
examples.javacodegeeks.com › home › java development › core java
Java not equal Example - Java Code Geeks
August 10, 2021 - The example code in this article was built and run using: ... 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.
🌐
iO Flood
ioflood.com › blog › java-notequals-operator
Java '!=' Operator: Use Cases for 'Not Equals' Comparisons
February 29, 2024 - When comparing objects, use ‘!=’ to check if they are different objects, and ‘equals()’ to compare their content. Always check if an object is not null before accessing its methods or fields using ‘!=’. By keeping these considerations in mind, you can avoid common pitfalls and use the ‘!=’ operator in Java effectively.
🌐
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.
🌐
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();
	
	
	
}

}

🌐
Delft Stack
delftstack.com › home › howto › java › not equals java
Not Equals in Java | Delft Stack
March 11, 2025 - In this example, we use the .equals() method to compare the contents of str1 and str2. Since both strings contain the same text, the output indicates that they are equal in content. This showcases the critical difference between using != and .equals(), emphasizing that != checks for reference equality, while .equals() checks for value equality. Understanding the concept of not equals in Java is essential for any programmer.
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...
🌐
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...
🌐
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").
🌐
Coderanch
coderanch.com › t › 394611 › java › strings-equal
Why are same strings not equal (Beginning Java forum at Coderanch)
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.
🌐
TutorialKart
tutorialkart.com › java › java-operators › java-not-equal-operator
Java Not Equal (!=) Operator
October 14, 2021 - Since values in x and y are not equal, x != y returned true.
🌐
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.
🌐
Coderanch
coderanch.com › t › 661872 › java › Comparing-String-Equal
Comparing a String to NOT Equal (Beginning Java forum at Coderanch)
If I am counting this correctly then I currently have two inner loops? Does your hint mean that I need to figure out how to have JUST an IF and Else statement with no FOR? Below is how I'm using the IF and ELSE IF statement . I thought that if I had an exclamation point it would read as "else if not character.equals to vowels " I know there are other ways to achieve the goal of this lesson and I want to explore those options as well but I want to learn what I'm doing wrong here first.
🌐
Medium
medium.com › @AlexanderObregon › javas-objects-equals-method-explained-3a84c963edfa
Java’s Objects.equals() Method Explained | Medium
5 days ago - Before the introduction of Objects.equals(), developers commonly relied on the == operator or the .equals() method to compare objects. However, these approaches come with their own set of challenges.
🌐
Modulo
ctp.mkprog.com › en › java › not_equal_to
Java | Not equal to: != | Easy language reference
Don't lose in a world of programming languages · Java · Not equal to operator is a logical operator that is used to compare two numbers. par1 != par2Used keywords: != par1 - Any number · par2 - Any number · Result - Logical value Returns a true, if the first number is Not equal to the second, ...
🌐
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 !
🌐
Hostman
hostman.com › tutorials › overriding the equals() method in java
Overriding the equals() Method in Java
December 26, 2025 - Another situation when a method is not overridden is the use of a class whose instances are pointless to compare. A good example is java.util.Random. The essence of this class is to return random sequences of numbers. Instances of this class must not be equal; otherwise, there is no point to them.
Price   $
Address   1999 Harrison St 1800 9079, 94612, Oakland