set java
Java
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) {}
}
} 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) {}
}
}
OUTPUT:
[34, 22, 10, 60, 30]
The sorted list is:
[10, 22, 30, 34, 60]
The First element of the set is: 10
The last element of the set is: 60A Set is a Collection that cannot contain duplicate elements.
The Set interface contains only methods inherited from Collection
and adds the restriction that duplicate elements are prohibited.
Also in Java:
- Title
- java console text color
- Category
- Java
- Title
- usaco 2018 january contest
- Category
- Java
- Title
- java map iteration
- Category
- Java
- Title
- java get keys from hashmap
- Category
- Java
- Title
- fibonacci sequence in java recursion
- Category
- Java
- Title
- from file to array java
- Category
- Java
- Title
- recursive function for fibonacci series in java javascript
- Category
- Java
- Title
- java uuid
- Category
- Java
- Title
- java for each
- Category
- Java
- Title
- pattern.compile java
- Category
- Java
- Title
- in dom parser how to find processing instruction in java
- Category
- Java
- Title
- java method
- Category
- Java
- Title
- in javascipt how to stop further page processing
- Category
- Java
- Title
- rock paper scissors java
- Category
- Java
- Title
- selection sort in java
- Category
- Java
- Title
- pascals triangle java
- Category
- Java
- Title
- Java array hashcode
- Category
- Java
- Title
- java check if int
- Category
- Java
- Title
- java save string in text file
- Category
- Java
- Title
- java hashtable
- Category
- Java
- Title
- how to skip a line in java
- Category
- Java
- Title
- Unrecognized option: --version Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit.
- Category
- Java
- Title
- jtable font size
- Category
- Java
- Title
- how make a final variable in java
- Category
- Java
- Title
- java string to int
- Category
- Java
- Title
- sqrt in java
- Category
- Java
- Title
- how to make array of objects in java and use it
- Category
- Java
- Title
- java how to call getReader twice
- Category
- Java
- Title
- programa que convierete un archi de c a java
- Category
- Java
- Title
- how to create a button in java
- Category
- Java
- Title
- string remove last character
- Category
- Java
- Title
- kotlin vs java
- Category
- Java
- Title
- jtable get get row
- Category
- Java
- Title
- java script snippet for responsive
- Category
- Java
- Title
- how to check if a list is empty java
- Category
- Java
- Title
- count the number of words in a string java
- Category
- Java
- Title
- java valeur absolue
- Category
- Java
- Title
- parseints(str) java
- Category
- Java
- Title
- cannot lock java compile cache as it has already been locked by this process
- Category
- Java
- Title
- java identifiers
- Category
- Java
- Title
- annotation spring notnull
- Category
- Java
- Title
- python vs java
- Category
- Java
- Title
- compile java
- Category
- Java
- Title
- how to delete an element from an array in java
- Category
- Java
- Title
- java insert array
- Category
- Java
- Title
- how to find the divisors of a number in java
- Category
- Java
- Title
- java string to integer
- Category
- Java
- Title
- String array into LinkedList java
- Category
- Java
- Title
- java question mark operator
- Category
- Java
- Title
- java create arraly list
- Category
- Java
- Title
- javafx textarea size
- Category
- Java
- Title
- how to install java 8 in ubuntu 16.04
- Category
- Java
- Title
- java import
- Category
- Java
- Title
- how to send http post create request using curl command
- Category
- Java
- Title
- How to create a 2d array in java
- Category
- Java
- Title
- download spring
- Category
- Java
- Title
- java script to detect and launch all browsers
- Category
- Java
- Title
- logging in java
- Category
- Java
- Title
- java constructor genertic
- Category
- Java
- Title
- array in java stack overflow
- Category
- Java
- Title
- toString convert to long
- Category
- Java
- Title
- récupérer les données d un liste java
- Category
- Java
- Title
- java list to array
- Category
- Java
- Title
- java string format .2f
- Category
- Java
- Title
- how to create a hashmap in java
- Category
- Java
- Title
- Create ArrayList from array java
- Category
- Java
- Title
- fragment button nullpointerexception
- Category
- Java
- Title
- how to set a variable java
- Category
- Java
- Title
- java how to get current date
- Category
- Java
- Title
- math minimum java
- Category
- Java
- Title
- comparable on a generic class java
- Category
- Java
- Title
- java program to get all cat indices in elasticsearch javadoc
- Category
- Java
- Title
- java quit application
- Category
- Java
- Title
- check if user has internet connection in kotlin
- Category
- Java
- Title
- demo java file
- Category
- Java
- Title
- get cursor position in textarea java
- Category
- Java
- Title
- arraylist array
- Category
- Java
- Title
- java 8 string to localdate
- Category
- Java
- Title
- byte java
- Category
- Java
- Title
- java get location of jar file
- Category
- Java
- Title
- java script print date in YYYY-MM-DD HH:MM:SS format
- Category
- Java
- Title
- cannot fit requested classes in a single dex file
- Category
- Java
- Title
- how to take binary input in java
- Category
- Java
- Title
- switch case java
- Category
- Java
- Title
- bootstrap button bigger
- Category
- Java
- Title
- java jaxb unmarshall xml to map
- Category
- Java
- Title
- how to print the map in java
- Category
- Java
- Title
- java best way to concatenate strings
- Category
- Java
- Title
- read and write files pattern java
- Category
- Java
- Title
- abs in java
- Category
- Java
- Title
- find maven version
- Category
- Java
- Title
- find numbers in a string java
- Category
- Java
- Title
- java array declaration
- Category
- Java
- Title
- get file path java
- Category
- Java
- Title
- Compare integers java sort
- Category
- Java
- Title
- absolute value java
- Category
- Java
- Title
- addition of two numbers in java
- Category
- Java
- Title
- java 8 loop in map
- Category
- Java
- Title
- How to loop through objects in java using streams
- Category
- Java
- Title
- java how to print a string[]
- Category
- Java