I'm having a problem deciding how to handle a situation. I'll briefly explain whats going on before I ask the question(s).

I have a viewObject (bean) and what it does is display information that is gathered. To keep it from getting too complicated I'll say I have 3 jLabels.

One jLabel (informationA) is gathered from a program that scans and saves to a file.csv.

jLabel two (informationB) and jLabel three (informationC) both are gathered from a database that is created by the user which is saved in file2.csv

To correctly have the information line up on this viewObject I am looking for a way to match them up.

[Question]
I was suggested to use a hashTable. So I looked it up and it seems fairly self explanatory, but was looking to see if someone could explain how to use it more specifically for my situation, or perhaps explain if there is a better solution.

If what I am wanting to do is still unclear I'll explain using an analogy. Lets say the first jLabel (informationA) is on the first object, I then want a certain informationB and informationC to be displayed on the same viewObject bean.

For instance lets say I have these strings:
[informationA]
Apple
Orange
Grape
Cherry

[informationB]
Round
Square
Triangle
Oval

[informationC]
Green
Orange
Purple
Red

Now obviously I want these to match up correctly so that they make sense, such as:

Apple , Round , Green

and not like:

Apple , Square , Orange

I was considering appending file2.csv to file.csv by using contains(). But I'm not sure if that is the smartest route to take.

Help and suggestions are welcome and appreciated

There's not enough info to be sure, but at first sight it looks like you should have a class Fruit, with name, shape and colour as instance variables. As you read the two files you could create the instances. Displaying the three values together is now trivial - just pass the Fruit instance to the viewObject. To keep track of the Fruit objects you could have a Hashtable with the Fruit's name as key and the actual Fruit instance as the value.

To keep track of the Fruit objects you could have a Hashtable with the Fruit's name as key and the actual Fruit instance as the value.

First of all thank you for your reply, you seem to be helpful in each of the threads I have posted. I've been a member and staff of multiple forums and it's hard to find people who are dedicated to helping. It's definitely appreciated, just thought I would share that with you.

As for my original question, I was sort of wondering how to do what I quoted above. As I have not yet toyed with hashtables, but read up on them. I kind of understand how they work, but don't feel I fully understand it. My viewObject has certain getters and setters which I am wanting to pull up the type of fruit and if that one is pulled up the other jLabels will get the shape, color, etc.

(fruit aren't what my program is about, but it was just an easier way of explaining the example)

Not sure exactly what the problem is here, so this answer may miss the point...
1. You create some number of Fruit objects, each has its getters & setters for the individual details.
2, You want to display one. But how do you know which one, and how do you get it?
3. Maybe: store them all in a hashtable, using their names as the key. That way you could, for example, populate a list box with the names then, when the user picks a particular name, use that to retrieve the Friut object, and pass that to a form that displays all its values.
4. If that doesn't help, I obviously don#t inderstand the question!

Perhaps I can explain it better.

Right now I have my viewObject. Upon opening of the program, it gets information from file1.csv file and displays it. So we will say the file1.csv contains the type of fruit.

Once that type of fruit is displayed is there a way to make that a key so that my other getters/setters can pull the information from the hashtable and put it on my viewobject?

If not, my overall problem is that I have a third party program that picks up certain information and saves it to a csv, while I have another program that is like a database and saves the info to another csv file. And I'm not quite sure how to display the information together without it getting the wrong information. (If that makes sense)

Best advice I can give you at the moment is to make a clear and absolute separation between how the data is acquired and how it is displayed, Think thru how a Fruit object can be instantiated and populated with data. Code and test that solution. When you've got that working, you can do a simple GUI to display it.

The data is acquired through two separate csv files (basically text files)

I'm having a problem of figuring out how to match them up, so that they can display properly.

My conclusion was perhaps a hashtable. Is there a better way than that?

> My conclusion was perhaps a hashtable

Doesn't seem logical since there are no "key => value" semantics here, just data which could be stuffed in a hash map. The solution here would be to let the DAO layer handle the querying of data, the controller handle the merging of data and what your UI/presentation layer gets is a nicely formatted list of Fruit objects. The Hash map approach breaks in case the data comes from more than 2 files [e.g. more attributes are added to the fruit object].

This article has been dead for over six months. Start a new discussion instead.