aspose file tools*
The moose likes Beginning Java and the fly likes I need help on arrays and array lists! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "I need help on arrays and array lists! " Watch "I need help on arrays and array lists! " New topic
Author

I need help on arrays and array lists!

Kay Jay
Greenhorn

Joined: Nov 16, 2009
Posts: 2
Hey everyone. I am trying to finish up a lab for my first java class ever, and boy am I struggling. I am trying to convert a method of arrays over to an array list. And while it seems like it should be simple, for whatever reason I am struggling. Any help would be great. Here's the method I have to re-write into an array list:



And here's my (failed attempt) at code so far:



HELP!
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

this.results(index)

You usually access elements of a List via the get(int index) method.


[My Blog]
All roads lead to JavaRanch
D. Ogranos
Ranch Hand

Joined: Feb 02, 2009
Posts: 214
Its usually cleaner to get the element you need from the list and store it to a local variable. Also helps you to avoid accessing the list multiple times. As said above, use the get() method of the list:



Also, check the if-condition...in the array example you're comparing to some value nextPos, while in the Arraylist part you compare to the list size.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I need help on arrays and array lists!