Best way to store data

jkteater
jkteater used Ask the Experts™
on
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!!!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
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.

Author

Commented:
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
Commented:
OK. So why not just have a class with four variables for Item, Rev, Name and Type. Something like:

class ItemDesc
{   int item,rev;
    String name,type;

    ItemDesc(int i,int r,String n,String t)
    {   item=i;
        rev=r;
        name=n;
        type=t;
    }
}

Then you can have an array of them:

ItemDesc id=new ItemDesc[num];

Initialize them all:

for(k=0; k<num; ++k)id[k]=new ItemDesc(i,r,n,t);

And then searching on them is just a matter of comparing variables; something like:

ItemDesc find(int i)
{    for(int k=0; k<num; ++k)
     {    if(id[k].item==i)return(id[k]);
     }
}
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);

Author

Commented:
I really like the class idea.  I am going to try and code that this afternoon.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial