Link to home
Start Free TrialLog in
Avatar of jkteater
jkteaterFlag for United States of America

asked on

Best way to store data

If I have

Item    Rev   Name   Type
100      01      foo       part
100      02      foo       part
101      01      foob     part

I want to store this data is data structure, so I can recall data when needed.

I don't think I can use a hash table because the key has to be unique.  

Looking for any suggestions!!!
Avatar of imladris
imladris
Flag of Canada image

The best data structure is dependant on the data size, how the data changes and how it needs to be read.

For instance, a hash table has quick retreival, and quick update, but it takes up more space than you have data. So if you have millions of records, that probably won't work very well.

A linked list is quick to update, space efficient, but it takes longer to find something in a list.

A sorted list is not as quick to update, still space efficient, and doesn't take as long to find something.

So the answer is, it depends on the characteristics of the situation.
Avatar of jkteater

ASKER

The data size is not going to be that large.  Where I am having a problem is keeping the data together.  Like the data above, I really need to keep the values together - Something like a object with attributes.  

For example -
I want to be able to take the first line you see up there.  Get the value for Item.
Then check the rest of the lines to see if Item has a match in the rest of the data.  If there is a match for Item, I then need to get the value for Type.  

Something like

For (int p, p not end of data structure, p++)
      get value item[p]
      for  (int j, j not end of data structure, j++)
         if item[p] == item[j]
            get value type[p]
            get value type[j]
            print type[p]
            print type[j]
         print no match found

I need to be able to store the name , type, etc with the row for item
ASKER CERTIFIED SOLUTION
Avatar of imladris
imladris
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sathish David  Kumar N
you can use java beans getter setter method ... set the 1st row values in java bean after that add the value to list ...

eg: x is my instance of my java bean calss
x.setIteam("x")
x.setRev("y");
X.setIteam("z");

arrayList1.add(x);
I really like the class idea.  I am going to try and code that this afternoon.