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) {}
}
}
Also in Java:
- when super add by constructor in java
- java prev permutation
- sort elements with sortedset
- how to get length of integer in java
- Java int to roman
- how to detect if someone clicks on a jpanel in java
- continue in java
- java create folder
- delete element from arraylist
- creating array java
- java timestamp
- change java version command line debian
- how to copy all files and subdirectories in directory in java
- dictionary in java
- java 8 stream group by example
- query java persistence
- java final meaning
- Matlab java.lang.IllegalArgumentException: Invalid range
- jquery set data attribute value
- java script removing first three indexes
- java parse xml string
- android how to know when snackbar is done
- how to install java 8 on terminal os
- how to check if a string is in alphabetical order in java