Deleting Duplicate Element Using HashSet

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import java.util.*;
 
public class Main {
 
    public static void main(String args[]){
 
    String[] fav = {"red","red","apple""apple""hallo"};
 
    Set<String> mySet  = new HashSet<String>();
    Collections.addAll(mySet,fav);
 
       System.out.println(mySet);
    }
}
cs

result / 결과

1
[red, apple, hallo]
cs

+ Recent posts