aspose file tools*
The moose likes Beginning Java and the fly likes [newbie] Vector of arrays...how to add them Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "[newbie] Vector of arrays...how to add them" Watch "[newbie] Vector of arrays...how to add them" New topic
Author

[newbie] Vector of arrays...how to add them

Jon Camilleri
Ranch Hand

Joined: Apr 25, 2008
Posts: 660

Any idea how to add some object to my Vector? As you might notice I'm trying to address what seems to be a common issue...a dynamically expanding array of objects, ideally of any type.



Related links: http://www.javaworld.com/javaworld/jw-08-1999/jw-08-cooltools.html


Jon
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

You are trying to mix a List of arrays of the primitive ints (int[]) with arrays of the Object Integer (Integer[]). An Integer is not the same as an int. You should make them both refer to the same data type:



- or -



Steve
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3014
    
  10
Jon Camilleri wrote:Any idea how to add some object to my Vector?

Um, have you tried the add() method?

Jon Camilleri wrote:As you might notice I'm trying to address what seems to be a common issue...a dynamically expanding array of objects, ideally of any type.

A common issue twenty or more years ago, maybe.

I tried reading the ten-year-old article you linked to, but I nearly died of boredom halfway through. I'm still recovering.

Look, whatever ancient text you're reading that talks about Vectors, please, just burn it and upgrade to something published in the current millenium.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38851
    
  23
Mike Simmons wrote:. . . in the current millenium.
If we are sticking to things from the current millennium, don't use Vector. It is generally regarded as legacy code. Use one of the more modern implementation of List<E>. Most likely ArrayList<E>.
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3014
    
  10
Yes, that was my point. One of them, at least.
Jon Camilleri
Ranch Hand

Joined: Apr 25, 2008
Posts: 660

Thanks
Jon Camilleri
Ranch Hand

Joined: Apr 25, 2008
Posts: 660

Thanks for your updates Well, actually I did try a modern day ArrayList, which is one of my favorite constructs in other languages, but I can't find a way of creating an array of integers:



Related Links:
1. http://www.roseindia.net/java/beginners/array_list_demo.shtml
2. The API http://java.sun.com/javase/6/docs/api/


Well the "solution" was quite simple... An ArrayList made up of an ArrayList of Integer (not int)



Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38851
    
  23
That roseindia demonstration was not really useful. It didn't tell you to declare your object by its interface. You would do better to declareFor some reason, which I don't know, I am getting >< when I typed <. Readers: please check for that error.

Anyway, why don't you declare the List to take int[] elements?
java IntArrayListDemo 123 234 345 456 567 678 789
And see for yourself what happens.
Jon Camilleri
Ranch Hand

Joined: Apr 25, 2008
Posts: 660

Campbell Ritchie wrote:That roseindia demonstration was not really useful. It didn't tell you to declare your object by its interface. You would do better to declareFor some reason, which I don't know, I am getting >< when I typed <. Readers: please check for that error.

Anyway, why don't you declare the List to take int[] elements?
java IntArrayListDemo 123 234 345 456 567 678 789
And see for yourself what happens.


Thanks, that seemed to work
My code did not seem to work when I tried implementing something on the same lines of thought (see above posts).



Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38851
    
  23
You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: [newbie] Vector of arrays...how to add them