Array Vs Vector

i have my own object (great, in'st it?). I need a list of this object. The list changes every 5-10min. When it changes, everything changes.Question: would array or vector be better?
[210 byte] By [Comp-Freaka] at [2007-11-27 9:20:31]
# 1

freakster,

I don't think it really matters, so use whichever you prefer.

Having said that I think I'd go for an array.

And BTW ArrayList is considered "the default" collection... I'd use it over a vector unless I had a compelling reason to do otherwise, like backwards compatibility with an existing library or something.

Keith.

corlettka at 2007-7-12 22:13:42 > top of Java-index,Java Essentials,Java Programming...
# 2

> i have my own object (great, in'st it?). I need a

> list of this object.

>

> The list changes every 5-10min.

> When it changes, everything changes.

>

> Question: would array or vector be better?

my own guess (and that's what it truly is), is that an ArrayList would be better unless you are worried about thready type things such as concurrency and synchronization, then go with vector. Anyone -- please correct if any errors.

thnx

petes1234a at 2007-7-12 22:13:42 > top of Java-index,Java Essentials,Java Programming...
# 3
Ill go for an array then, if it doesn't work out Ill just swich.Thanks GuysIll = i L L (just normal capitalization)
Comp-Freaka at 2007-7-12 22:13:42 > top of Java-index,Java Essentials,Java Programming...
# 4
Oh yeah, Vector is thread safe, and ArrayList isn't... I forgot that bit coz I'm not writing threaded apps (yet).But is an array inherently thread safe? I don't suppose it is.Keith.
corlettka at 2007-7-12 22:13:42 > top of Java-index,Java Essentials,Java Programming...
# 5

> unless you are worried about thready type things such as concurrency and

> synchronization

The ArrayList API documentation suggests using Collections.synchronizedList() to get a synchronised list.

One place a Vector might be useful is if a JList is being used to display the list, as these things can be constructed using a Vector as the basis of their model.

Another List implementation is the LinkedList. ArrayList implements RandomAccess, while LinkedList implements Queue. Performance differences are considered here: http://java.sun.com/developer/JDCTechTips/2002/tt0910.html

pbrockway2a at 2007-7-12 22:13:42 > top of Java-index,Java Essentials,Java Programming...
# 6

I ran into this problem:

MyObject[] MyObjects = new MyObject[text.getItemCount()];

for (int i = 0; i < MyObjects.length; i++)

{

MyObjects[i] = new MyObject();

MyObjects[i].Load(Name, text.getItem(i)); // performs a procedure on my object, i get error here.

}

Nullpointerexception... What did i forget?

btw

- text (a list-textfile) was successfully loaded.

- when MyObject is created with hand the procedure Load works.

Comp-Freaka at 2007-7-12 22:13:42 > top of Java-index,Java Essentials,Java Programming...
# 7
What exactly are you trying to do... In English first, then we'll work on the Java?And you really need to the camelCase thing... I can't tell your variables from your Classes.
corlettka at 2007-7-12 22:13:43 > top of Java-index,Java Essentials,Java Programming...
# 8

> I ran into this problem:

> MyObject[] MyObjects = new

> MyObject[text.getItemCount()];

> for (int i = 0; i < MyObjects.length; i++)

> {

> MyObjects[i] = new MyObject();

> MyObjects[i].Load(Name, text.getItem(i)); //

> // performs a procedure on my object, i get error

> here.

> }

>

> Nullpointerexception... What did i forget?

>

> btw

> - text (a list-textfile) was successfully loaded.

> - when MyObject is created with hand the procedure

> Load works.

Looks like time to put a bunch of System.out.println() statements in. I'd pay particular attention to what text and what text.getItem(i) are at the time of the loop.

petes1234a at 2007-7-12 22:13:43 > top of Java-index,Java Essentials,Java Programming...
# 9
> The ArrayList API documentation suggests using> Collections.synchronizedList() to get a synchronised> list.Thanks pbrockway, I had not previously heard of this collection.
petes1234a at 2007-7-12 22:13:43 > top of Java-index,Java Essentials,Java Programming...