Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

java problem

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
Thank you very much.
Peter
 
reply
    Bookmark Topic Watch Topic
  • New Topic