Vladimir Korabelnikoff

Greenhorn
+ Follow
since Oct 21, 2011
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
7
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Vladimir Korabelnikoff

Joanne Neal wrote:Have you been told to use a list of lists ?
The better solution is to create a Company class and an Employee class and the Company class will contain a list of Employees.

Off topic - your list of employees reminds me of a Monty Python sketch.



I'm sure I have been told to do lists, and that's what I'm using? Maybe I missed something.

I'm not actually sure what you mean by having a class for companies and employees. I only need one company, and multiple employees.

Edit: Haha, why so? I've only seen one Monty Python sketch (The Holy Grail) - The funniest stuff ever.
12 years ago

Campbell Ritchie wrote:You ought to have declared it as Rob told you. You can iterate a List<List<Foo>> in a for-each loop, with each element found being a List<Foo>. Like this:



Awesome! Thank you guys so much! You are legends! I have gotten it to work. I now read the XML, and put into a List of Lists, then return that back to the main class.

Now I have to figure out how to sort through them (by certain fields)/

This is the XML:



I need to be able to order it by date (ascending, and descending). The date is of course, in UNIX timestamp.

Note that I'm not sorting XML, I'm sorting through the List of Lists.

Can you guy please point me in the right direction? Thanks so much for your help.

12 years ago

Rob Spoor wrote:Collections can hold any objects, and that includes other collections. At least if you use the right generic type:



Thanks for that. I created an ArrayList of ArrayLists.

However, I have a nested for loop where I read my XML, and I have no idea how to name the sub-Lists in the for loop.


That's alright for the first loop, but what happens when it comes back a second time? singleLists should be renamed, if I'm correct.

I'm just not sure how :l Thanks for your help, guys.
12 years ago

Campbell Ritchie wrote:There is no such thing as a multidimensional array, only an array of arrays. There is no such thing as a multidimensional ArrayList, but you can have a List of Lists.



Oh Really? That's awesome! Can you put any type of Collection inside of a Collection? Or is it just Lists?
12 years ago

Paul Clapham wrote:

Vladimir Korabelnikoff wrote:Or, would I be better off creating a new array (and copying the other array to the new one) every time I add an element to it?



But that's basically what an ArrayList does. So if that's what you need then use an ArrayList.



Thanks a bunch! I'll look into how to make ArrayLists's multidimensional!
12 years ago
So I need to be able to store data from an xml file in a collection.

The output is the equivalent of a two-dimensional table.

I need to be able to EXPAND it, so Array is almost not an option.

Would I be better off trying to use a multidimensional arraylist?

Or, would I be better off creating a new array (and copying the other array to the new one) every time I add an element to it?


Please let me know ;) Thanks guys!
12 years ago

Bear Bibeault wrote:Well, List is an interface, so you cannot create an instance of it. In fact, ArrayList is one of the container classes that implements List. What you need to do is to look through the collection classes that implement List and choose the one that best meets your requirements.

Welcome to the Ranch.



Thanks! I didn't realize that! I'm looking at the Java API now.
12 years ago
This is my first post here, I'm not sure if this is in the right forum.

I'm reading data from an XML file, and storing it in temporary memory so that I can:

* Read
* Update individual entries
* Search
* Sort by ascending/descending order (date column)
* Add more then save to the XML file
* Deleting entries
* Updating entries

I need an expandable object to use. Obviously arrays do not suit.

So would I be better off using Lists or Arraylists?
12 years ago