This Java Example shows how to check whether a particular value exists in LinkedHashSet or not.
Check value is exists In Java LinkedHashSet Example
This Java Example shows how to check whether a particular value exists in LinkedHashSet or not. To check whether a particular value exists in LinkedHashSet We use boolean contains(Object value) method of LinkedHashSet class. It returns true if a specified object is an element within the collection otherwise false.
Example:- CheckValueInLinkedHashSet.java
package devmanuals.com;
import java.util.LinkedHashSet;
public class CheckValueInLinkedHashSet {
public static void main(String args[]) {
LinkedHashSet LHSet = new LinkedHashSet();
LHSet.add("C");
LHSet.add("A");
LHSet.add("B");
LHSet.add("E");
LHSet.add("F");
LHSet.add("D");
System.out.println("The LinkedHashSet elements are: " + LHSet);
System.out.println("Is B is exists : " + LHSet.contains("B"));
}
}
Output:-
| The LinkedHashSet elements are: [C, A, B, E, F, D]
Is B is exists : true |

[ 0 ] Comments