I read in a text file to created a hashmap based on the users id which is unique. This works fine, however, I also need to extract the users name, but I only need the name once and sorted. I am trying to do this with a hashset with some success. I can get the data but there are duplicates and it's not sorting. I thought the hashset would do this automatically.
Is it possible to extract this data into a hashset from the hashmap as describe above? I've put a sample of hashmap.
Is it possible to extract this data into a hashset from the hashmap as describe above? I've put a sample of hashmap.
Code:
HashMap value = new HashMap();
/** Creates new form TestHashMap */
public void fileRead() throws Exception
{
FileReader fr = new FileReader("C://Documents and Settings//epeak//My Documents//test.txt");
BufferedReader br = new BufferedReader(fr);
String s;
while((s = br.readLine()) != null) {
Pattern p = Pattern.compile("[\\s]+");
String[] str = p.split(s);
// System.out.println(str[0] + " "+str[1] +" "+str[2]+" "+str[3]);
Propertyunbuf prop = new Propertyunbuf();
prop.setPropertyId(str[0]);
prop.setPropertyName(str[1]);
prop.setPropertyValue( new Double(str[2]));
// prop.setPropertyValue(new Double(str[2]).doubleValue());
prop.setAgendId(str[3].trim());
// System.out.println(str[1]);
HashSet ref = new HashSet(); // create a HashSet
Iterator i = ref.iterator(); // get iterator
System.out.println( "\nNonduplicates are: " );
while ( i.hasNext() )
System.out.print( i.next() + " " );
System.out.println();
Comment