Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I need help on arrays and array lists!

 
Kay Jay
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this.results(index)

You usually access elements of a List via the get(int index) method.
 
D. Ogranos
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic