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.
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: 2782
2
posted
0
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: 32712
4
posted
0
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>.
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:
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: 32712
4
posted
0
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?
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).