//HashSet is used to remove the duplicate term in the list
import java.util.*;
public class HackDefence{
public static void main(String[] args){
String[]country = {"India","Pakistan","America","India","China"};
List<String> countryList = Arrays.asList(country);
System.out.printf("Before the use of HashSet :" + "%s",countryList);
System.out.println();
Set<String>set = new HashSet<String>(countryList);
System.out.printf("After the use of HashSet :" + "%s",set);
}
}
OUTPUT:
import java.util.*;
public class HackDefence{
public static void main(String[] args){
String[]country = {"India","Pakistan","America","India","China"};
List<String> countryList = Arrays.asList(country);
System.out.printf("Before the use of HashSet :" + "%s",countryList);
System.out.println();
Set<String>set = new HashSet<String>(countryList);
System.out.printf("After the use of HashSet :" + "%s",set);
}
}
OUTPUT:
No comments:
Post a Comment