File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

java problem

peterx peter
Greenhorn

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:
http://java.sun.com/docs/books/tutorial/java/data/arrays.html

There's also an Array class in Java--you can make full-fledged Objects of type Array--err, actually, they call it Arrays:
http://java.sun.com/j2se/1.4.2/docs/api/java/util/Arrays.html

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
Greenhorn

Joined: Nov 02, 2004
Posts: 19
Hi!
Thank you very much.
Peter
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java problem