"java set operations" Code Answer's
You're definitely familiar with the best coding language Java that developers use to develop their projects and they get all their queries like "java set operations" answered properly. Developers are finding an appropriate answer about java set operations related to the Java coding language. By visiting this online portal developers get answers concerning Java codes question like java set operations. Enter your desired code related query in the search bar and get every piece of information about Java code related question on java set operations.
set in java
SET: Can only store unique values,
And does not maintain order
- HashSet can have null, order is not guaranteed
- LinkedHashSet can have null and keeps the order
- TreeSet sorts the order and don't accept null
java set example
import java.util.*;
public class SetDemo {
public static void main(String args[]) {
int count[] = {34, 22,10,60,30,22};
Set<Integer> set = new HashSet<Integer>();
try {
for(int i = 0; i < 5; i++) {
set.add(count[i]);
}
System.out.println(set);
TreeSet sortedSet = new TreeSet<Integer>(set);
System.out.println("The sorted list is:");
System.out.println(sortedSet);
System.out.println("The First element of the set is: "+ (Integer)sortedSet.first());
System.out.println("The last element of the set is: "+ (Integer)sortedSet.last());
}
catch(Exception e) {}
}
}
Source: www.tutorialspoint.com
java set operations
s1.containsAll(s2) — returns true if s2 is a subset of s1. (s2 is a subset of s1 if set s1 contains all of the elements in s2.)
s1.addAll(s2) — transforms s1 into the union of s1 and s2. (The union of two sets is the set containing all of the elements contained in either set.)
s1.retainAll(s2) — transforms s1 into the intersection of s1 and s2. (The intersection of two sets is the set containing only the elements common to both sets.)
s1.removeAll(s2) — transforms s1 into the (asymmetric) set difference of s1 and s2. (For example, the set difference of s1 minus s2 is the set containing all of the elements found in s1 but not in s2.)
All those coders who are working on the Java based application and are stuck on java set operations can get a collection of related answers to their query. Programmers need to enter their query on java set operations related to Java code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about java set operations for the programmers working on Java code while coding their module. Coders are also allowed to rectify already present answers of java set operations while working on the Java language code. Developers can add up suggestions if they deem fit any other answer relating to "java set operations". Visit this developer's friendly online web community, CodeProZone, and get your queries like java set operations resolved professionally and stay updated to the latest Java updates.