package com.po2cls.actions;
import java.util.Arrays;
import java.util.HashSet;
public class RemoveDuplicatesinArray {
public void removeDuplicates() {
String[] cityString = new String[10];
cityString[0] = "Hyderabad";
cityString[1] = "Bangalore";
cityString[2] = "Hyderabad";
cityString[3] = "Bangalore";
cityString[4] = "Hyderabad";
cityString[5] = "Mumbai";
cityString[6] = "Hyderabad";
cityString[7] = "Mumbai";
cityString[8] = "Hyderabad";
cityString[9] = "Chennai";
HashSet<String> cityHashSet = new HashSet<String>(Arrays.asList(cityString));
System.out.println("cityHashSet" + cityHashSet.toString());
}
public static void main(String[] args) {
new RemoveDuplicatesinArray().removeDuplicates();
}
}
Output:
cityHashSet :: [Chennai, Bangalore, Mumbai, Hyderabad]
import java.util.Arrays;
import java.util.HashSet;
public class RemoveDuplicatesinArray {
public void removeDuplicates() {
String[] cityString = new String[10];
cityString[0] = "Hyderabad";
cityString[1] = "Bangalore";
cityString[2] = "Hyderabad";
cityString[3] = "Bangalore";
cityString[4] = "Hyderabad";
cityString[5] = "Mumbai";
cityString[6] = "Hyderabad";
cityString[7] = "Mumbai";
cityString[8] = "Hyderabad";
cityString[9] = "Chennai";
HashSet<String> cityHashSet = new HashSet<String>(Arrays.asList(cityString));
System.out.println("cityHashSet" + cityHashSet.toString());
}
public static void main(String[] args) {
new RemoveDuplicatesinArray().removeDuplicates();
}
}
Output:
cityHashSet :: [Chennai, Bangalore, Mumbai, Hyderabad]
No comments:
Post a Comment