Results 1 to 20 of 25
Thread: Parallel Array Lists?
- 05-18-2011, 01:08 AM #1
Senior Member
- Join Date
- Mar 2011
- Posts
- 261
- Rep Power
- 10
- 05-18-2011, 01:18 AM #2
How do you want to access the data?
With a Map, the key could be the host, and the value could be a list of ports.
if you want the value to be heterogeneous (ie different types) make your own class to hold the variable bits and pieces and lists that you want to save for each host.
- 05-18-2011, 01:25 AM #3
Senior Member
- Join Date
- Mar 2011
- Posts
- 261
- Rep Power
- 10
- 05-18-2011, 01:58 AM #4
How would you describe the "theoretical" list you want to create?
What would an element in the list look like?
What would be returned if you did a get(ix)?
As I said before: make your own class to hold the variable bits and pieces and lists that you want to put in container.
- 05-18-2011, 02:15 AM #5
I have to echo Norm, really. Making your own class would probably solve all your problems, and it would make it much easier to add additional data or change the structure at a later date (you wouldn't have to rewrite all the arrays, lists or maps, for instance).
- 05-18-2011, 02:29 AM #6
My 0.02¢
Beware, it you are going to make a class simply to hold a bunch of disparate data then I smell a design flaw.
- 05-18-2011, 02:58 AM #7
- 05-18-2011, 03:21 AM #8
The whole point of OO design is to hold related data together. For example a Person object holds a name, address, DOB etc. All the information about a person.
You do not create a class to hold the atomic weight of an atom, the name of your first pet, the interest rate of your home loan and the clock speed of your computer. This is what I mean by disparate data.
- 05-18-2011, 03:24 AM #9
In this case though, the data is related. It'd be like holding the atom number, the number of protons, the mole-weight and such. I definitely agree with you on not bunching disparate data together, but as far as I understood it, that is not the case here.
- 05-18-2011, 05:05 AM #10
Senior Member
- Join Date
- Mar 2011
- Posts
- 261
- Rep Power
- 10
Ok well what I'm using the list for is this:
I have a Main class and a Proxy (object) class. Every proxy has a host and a port right?
So in my Main class I'm reading a text file for hosts and ports of proxies, and I want to have a list of hosts and their respective ports. Then, I would create new Proxy objects with the hosts and ports in my list.
- 05-18-2011, 05:15 AM #11
So, to echo what Toll said earlier, you probably want to use an ArrayList<Proxy>.
- 05-18-2011, 05:18 AM #12
Senior Member
- Join Date
- Mar 2011
- Posts
- 261
- Rep Power
- 10
- 05-18-2011, 05:22 AM #13a way I could prepare the whole list before I start creating Proxy objects
If you don't have any objects yet, how can you prepare the whole list?
You'd add the objects to the list one by one as you create them.
- 05-18-2011, 05:24 AM #14
Senior Member
- Join Date
- Mar 2011
- Posts
- 261
- Rep Power
- 10
The list isn't a list of objects here. I'm trying to prepare a list in order to create Proxy objects. Just a list of a string and an int, host and port.
In fact, forget the Proxy objects. I'm trying to get a list of a string and an int.
Instead of just using two lists - one for the hosts and one for the ports, can I have one list with both?Last edited by Solarsonic; 05-18-2011 at 05:28 AM.
- 05-18-2011, 05:28 AM #15
I don't know of any lists that would take data types of int and String.
Seems strange to have a list like:
1, 2, "apple", 44, "house", "horse", 99, ...
- 05-18-2011, 05:44 AM #16
Senior Member
- Join Date
- Mar 2011
- Posts
- 261
- Rep Power
- 10
See, what would work here is a HashMap because there's two values that correspond with another, which is where I got the "parallel array lists", kind of like "parallel arrays" in that they're two objects that correspond with each other.
And how you're saying it's strange, it doesn't seem strange to me to have host (string) and port (int) correspond with each other?
But what would I do if there were 3 values that were corresponding? I couldn't use a HashMap then right?
I could just use two ArrayLists: a String arraylist and an Integer arraylist, but as parallel arrays are generally discouraged I'm wondering if there's a better way of doing this.
- 05-18-2011, 05:45 AM #17
How about a map?
Java Code:Map<String, ArrayList<String>>
- 05-18-2011, 05:47 AM #18
Senior Member
- Join Date
- Mar 2011
- Posts
- 261
- Rep Power
- 10
- 05-18-2011, 05:51 AM #19
- 05-18-2011, 05:53 AM #20
Senior Member
- Join Date
- Mar 2011
- Posts
- 261
- Rep Power
- 10
Similar Threads
-
array lists in jsp and google api
By gedas in forum New To JavaReplies: 3Last Post: 04-07-2011, 03:18 PM -
Array Lists help!!
By lilika in forum New To JavaReplies: 12Last Post: 01-04-2011, 03:05 PM -
Array Lists and Club class
By amekjian in forum New To JavaReplies: 13Last Post: 11-03-2010, 01:42 AM -
Help with arrays and array lists
By ambernicole88 in forum New To JavaReplies: 3Last Post: 12-04-2009, 10:47 PM -
please i need the code of comparing these two array lists.
By raj reddy in forum JavaServer Pages (JSP) and JSTLReplies: 5Last Post: 04-18-2008, 08:42 AM
Bookmarks