• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java Collection issue

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
am facing issue on how to store and then retrieve data . In my program which is simple java class i am retrieving data at 3 places from an xml. i need to store this temporarly in particular fashion as data is related and needed to be used later on at end program to generate report.

first data i am retireving is employee names eg Tom , Reggie, Martha.
Second data is department (Each employee belongs to 1 or many department ) so in this case

Tom : Billing
Reggie : Admin , HR
Martha : IT

Third data is Department number (This has 1 : 1 relationship with Department )
Billing :01
Admin :02
HR:03
IT:04

So when i am parsing xml first i am getting employee data, then department and lastly department number. I need to store it in collection in such way later on i can retireve and link data and use it.....

Which java collections i should use....
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"zaxxon25",
Welcome back to the JavaRanch.

We're a friendly group, but we do require members to have valid display names.

Display names must be two words: your first name, a space, then your last name. Fictitious names are not allowed.

Please edit your profile and correct your display name since accounts with invalid display names get deleted.

This is the final request before we close your account.

thanks,
Dave.
 
Ranch Hand
Posts: 111
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi zaxxon25 (Please make it realistic),

I suppose the third data of Department number is fixed so you can use class scope
hashtable which will be populated only once, for the other data you can create a bean ( inner class or outer if your project permits)

class EmpTempData{

public EmpTempData(Hashtable deptNumbers){
this.deptNumber=deptNumbers;
}
private String empName;
private ArrayList empDepartment;
/*
containing "deptName" and "deptNumber" pair
*/
private Hashtable deptNumbers;

//getter setter methods of empName,empDepartment and deptNumbers

// method to get department numbers corresponding to department name

public Hashtable getEmpDeptNameAndNumber(){
// implementation
}
}
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic