• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java problem

 
peterx peter
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Steven Bell
Ranch Hand
Posts: 1071
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 618
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
Thank you very much.
Peter
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic