0% found this document useful (0 votes)
3 views1 page

Common Set Methods in Java

Uploaded by

balapaithara79
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Common Set Methods in Java

Uploaded by

balapaithara79
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Set<String> set = new HashSet<>();

[Link]("Apple");

Common Methods of Set

Method Description

add(E e) Adds an element if not already present.

remove(Object o) Removes an element.

contains(Object o) Checks if an element exists in the set.

size() Returns the number of elements.

isEmpty() Checks if the set is empty.

clear() Removes all elements.

iterator() Returns an iterator for traversal.

for (String item : set) {

[Link](item);

import [Link];

Iterator<String> iterator = [Link]();

while ([Link]()) {

[Link]([Link]());

LinkedHashSet (Maintains Insertion Order

import [Link];

Set<String> linkedSet = new LinkedHashSet<>();

TreeSet (Sorted Order)

You might also like