Urgent: Sort HashSet() function data in sequence

Posted by vincent low on Stack Overflow See other posts from Stack Overflow or by vincent low
Published on 2010-03-28T18:24:13Z Indexed on 2010/03/28 18:33 UTC
Read the original article Hit count: 376

Filed under:
|

i am new to java, the function i like to perform is something like:

i will load a series of data from a file, into my hashSet() function.

the problem is, i able to enter all the data in sequence, but i cant retrieve it out in sequence base on the account name in the file.

any 1 can help to give a comment?

below is my code:

public Set retrieveHistory(){ Set dataGroup = new HashSet(); try{

        File file = new File("C:\\Documents and Settings\\vincent\\My Documents\\NetBeansProjects\\vincenttesting\\src\\vincenttesting\\vincenthistory.txt");

        BufferedReader br = new BufferedReader(new FileReader(file));
        String data = br.readLine();
        while(data != null){
            System.out.println("This is all the record:"+data);
            Customer cust = new Customer();
            //break the data based on the ,
            String array[] = data.split(",");
            cust.setCustomerName(array[0]);
            cust.setpassword(array[1]);
            cust.setlocation(array[2]);
            cust.setday(array[3]);
            cust.setmonth(array[4]);
            cust.setyear(array[5]);
            cust.setAmount(Double.parseDouble(array[6]));
            cust.settransaction(Double.parseDouble(array[7]));
            dataGroup.add(cust);
            //then proced to read next customer.

            data = br.readLine();
        } 
        br.close();
    }catch(Exception e){
        System.out.println("error" +e);
    }
    return dataGroup;
}

public static void main(String[] args) {
    FileReadDataModel fr = new FileReadDataModel();
    Set customerGroup = fr.retrieveHistory();
  System.out.println(e);
    for(Object obj : customerGroup){
        Customer cust = (Customer)obj;

        System.out.println("Cust name :" +cust.getCustomerName());
        System.out.println("Cust amount :" +cust.getAmount());

    }

© Stack Overflow or respective owner

Related posts about java

Related posts about jframe