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) {}
}
}
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 sleep in code
- Category
- Java
- Title
- selection sort in java
- Category
- Java
- Title
- java how to call getReader twice
- Category
- Java
- Title
- java sort method
- Category
- Java
- Title
- how to add jar in maven java application in netbeans
- Category
- Java
- Title
- arraylist array
- Category
- Java
- Title
- number to char java
- Category
- Java
- Title
- java hash password
- Category
- Java
- Title
- arraylist to int array java
- Category
- Java
- Title
- java double 2 decimal
- Category
- Java
- Title
- eclipse does not support logback with spring boot
- Category
- Java
- Title
- raise number to power java
- Category
- Java
- Title
- how to minimize jframe in java
- Category
- Java
- Title
- sort elements with sortedset
- Category
- Java
- Title
- android studio keep device awake
- Category
- Java
- Title
- show menuitem when menu hovered javafx
- Category
- Java
- Title
- java how to read a text file
- Category
- Java
- Title
- how to check if rs next is null
- Category
- Java
- Title
- how to remove all whitespace from string java
- Category
- Java
- Title
- java setter
- Category
- Java
- Title
- how to create an action listener in java
- Category
- Java
- Title
- how to play a clip of audio in java when needed
- Category
- Java
- Title
- how to iterate list in java selenium
- Category
- Java
- Title
- get long from date java
- Category
- Java
- Title
- Filebody in java
- Category
- Java
- Title
- convert char to string java
- Category
- Java
- Title
- boolean checkbox swing
- Category
- Java
- Title
- arraylist to array java
- Category
- Java
- Title
- print out value java
- Category
- Java
- Title
- how to change actionbar color in android programmatically
- Category
- Java
- Title
- java length of matrix
- Category
- Java
- Title
- Fab to CircularRevealFrameLayout example
- Category
- Java
- Title
- in javascipt how to stop further page processing
- Category
- Java
- Title
- java vs javascript
- Category
- Java
- Title
- java long to int
- Category
- Java
- Title
- reverse linked list in java to get both head and tail
- Category
- Java
- Title
- how to remove all components from layeredPane java
- Category
- Java
- Title
- how to compare string in java
- Category
- Java
- Title
- list in java
- Category
- Java
- Title
- refrence xml textfield in javafx
- Category
- Java
- Title
- same method name with different arguments
- Category
- Java
- Title
- java how to compare strings
- Category
- Java
- Title
- java list to set
- Category
- Java
- Title
- java 8 list stream delete by name
- Category
- Java
- Title
- java display message
- Category
- Java
- Title
- java get command line input
- Category
- Java
- Title
- java logical operator
- Category
- Java
- Title
- how to open a text file in java
- Category
- Java
- Title
- exponents java
- Category
- Java
- Title
- java delay
- Category
- Java
- Title
- java read from file
- Category
- Java
- Title
- Java for loop
- Category
- Java
- Title
- elasticsearch api code call using highlevelrestclient
- Category
- Java
- Title
- priority queue java reverse order
- Category
- Java
- Title
- applicationcontext.xml
- Category
- Java
- Title
- java override equals and hashcode
- Category
- Java
- Title
- java open file
- Category
- Java
- Title
- spigot deal damage
- Category
- Java
- Title
- java obtain list string from list object
- Category
- Java
- Title
- even or odd in java
- Category
- Java
- Title
- int to string java
- Category
- Java
- Title
- convert localdatetime to localdate
- Category
- Java
- Title
- java max
- Category
- Java
- Title
- how to call a static method in java
- Category
- Java
- Title
- java create map
- Category
- Java
- Title
- system.out.println shortcut
- Category
- Java
- Title
- demo java file
- Category
- Java
- Title
- change fab image programatically
- Category
- Java
- Title
- cosinus-1 java
- Category
- Java
- Title
- Java script code for add
- Category
- Java
- Title
- java read from connection even if 404
- Category
- Java
- Title
- read lines of file randomly java
- Category
- Java
- Title
- how to declare list of object in java as constant
- Category
- Java
- Title
- java prev permutation
- Category
- Java
- Title
- 2 decimal places print format JAVA
- Category
- Java
- Title
- jtable font size
- Category
- Java
- Title
- in java how to compare two strings
- Category
- Java
- Title
- android java shared preferences remove key
- Category
- Java
- Title
- java lerp
- Category
- Java
- Title
- prime factorization java
- Category
- Java
- Title
- contains example in java
- Category
- Java
- Title
- number of matches regex java
- Category
- Java
- Title
- copy array in java
- Category
- Java
- Title
- java read file bufferedreader
- Category
- Java
- Title
- libgdx move camera with touch
- Category
- Java
- Title
- isSelfDivisor java
- Category
- Java
- Title
- gravity in java
- Category
- Java
- Title
- java pass array as method parameter
- Category
- Java
- Title
- java script removing first three indexes
- Category
- Java
- Title
- android notification addaction example
- Category
- Java
- Title
- java script dynamic varibale creation
- Category
- Java
- Title
- create object of static class in java
- Category
- Java
- Title
- java call another constructor
- Category
- Java
- Title
- How to create a 2d array in java
- Category
- Java
- Title
- java get size of array
- Category
- Java
- Title
- get first 5 characters of string java
- Category
- Java
- Title
- recursive function for fibonacci series in java javascript
- Category
- Java
- Title
- how to add multiple filter condition in Java stream filter chain
- Category
- Java
- Title
- java round up
- Category
- Java
- Title
- download spring
- Category
- Java