- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Comparing Enumeration Values in Java
To compare enumeration values, use the equals() method.
Our Devices enum is having some objects with values assigned to them.
Devices d1, d2, d3; d1 = Devices.LAPTOP; d2 = Devices.LAPTOP; d3 = Devices.TABLET;
Let us compare them −
if(d3.equals(Devices.TABLET)) System.out.println("Devices are same."); else System.out.println("Devices are different.");
The following is an example −
Example
public class Demo { enum Devices { LAPTOP, MOBILE, TABLET; } public static void main(String[] args) { Devices d1, d2, d3; d1 = Devices.LAPTOP; d2 = Devices.LAPTOP; d3 = Devices.TABLET; if(d1.equals(d2)) System.out.println("Devices are same."); else System.out.println("Devices are different."); if(d3.equals(Devices.TABLET)) System.out.println("Devices are same."); else System.out.println("Devices are different."); } }
Output
Devices are same. Devices are same.
- Related Articles
- Comparing Strings with (possible) null values in java?
- Enumeration in Java
- Get Enumeration over HashSet in Java
- Difference between Iterator and Enumeration in Java
- Comparing corresponding values of two arrays in JavaScript
- Difference Between Iterator and Enumeration Interface in Java
- Comparing enum members in Java\n
- Get Enumeration over ArrayList with Java Collections
- Java Program to convert HashSet to Enumeration
- Comparing two Strings lexicographically in Java \n
- Comparing Strings and Portions of Strings in Java
- Traverse a collection of objects using the Enumeration Interface in Java
- What is the difference between Enumeration interface and enum in Java?
- Remove values in an array by comparing the items 0th index in JavaScript?
- What is enumeration in C#?

Advertisements