• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help converting to ArrayList

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need help converting my code into an ArrayList. We are only supposed to use an ArrayList and not an array. I didn't see that part of my project and not too good with using ArrayList. Please help me figure this out.


 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Robert Harp wrote:I need help converting my code into an ArrayList. We are only supposed to use an ArrayList and not an array. I didn't see that part of my project and not too good with using ArrayList. Please help me figure this out.


It's fairly straightforward:
  • Every place you have 'X[]', replace it with 'List<X>' (note: much better than 'ArrayList<X>').
  • Every place you have 'new X[n]', replace it with 'new ArrayList<X>(n)'.
  • Every place you have 'arrayname[n]' that is not followed by an '=' sign, replace it with 'listname,get(n)'.

  • The only other thing to deal with is initializing its values, and the easiest way to do that is to add them in the order you want. Have a look at the API docs for ArrayList.add() for details.

    HIH

    Winston
     
    Marshal
    Posts: 79151
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    And welcome to the Ranch
    reply
      Bookmark Topic Watch Topic
    • New Topic