I have to manipulate strings present under a big HashSet Object and I would like to know if there is any possibility of manipulating existing HashSet object with out creating a new HashSet object
Below is my current logic, in which, I wanted to avoid the creation of 2nd HashSet (set2
object).
HashSet<String> set1 = new HashSet<String>();
set1.add("AB.12");
set1.add("CD.34");
set1.add("EF.56");
set1.add("GH.78");
HashSet<String> set2 = new HashSet<String>();
for(String data : set1) {
set2.add(data.substring(0,2));
}
P.S.: The reason for going for a Set is to avoid duplicate entries (come from different source).