File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes java problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java problem" Watch "java problem" New topic

java problem

peterx peter

Joined: Nov 02, 2004
Posts: 19
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
I'm not sure what exactly you have there, but it's not a Vector. What you are calling a Vector is an Array of ints. The size of an Array cannot be changed.

Plus you have other logic problems. As far as I can tell from looking at your code you will never get into any of the for loops.
Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
This Sun page explains the primitive array type in Java:

There's also an Array class in Java--you can make full-fledged Objects of type Array--err, actually, they call it Arrays:

Or you can make a primitive array like you're doing. But FYI, I typically would use a List for what you want to do, and most often I find myself using a LinkedList, although if I need synchronization I might use a Vector. There are plenty of others you can use, and tons of tutorials on Google that explain the rest of the Collections Framework.

That's a lot of reading, so just focus on the bits you need. List is what's called an interface, so you can't make one directly. Instead, you need to use one of the classes that implement it, like LinkedList. Here's the proper way to do it:

These List objects will automatically grow as you add to them, so you don't have to know ahead of time how big to make them. For reasons I won't go into here, it's generally best to declare it as an object of a certain interface rather than the implementing class. If you don't get that sentence, then ignore it.

Have fun...
peterx peter

Joined: Nov 02, 2004
Posts: 19
Thank you very much.
I agree. Here's the link:
subject: java problem
jQuery in Action, 3rd edition