Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ArrayList Manipulation

 
Dave DiRito
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For this problem I need to find the smallest integer in an ArrayList and move it to the front of the list without changing the order of the other list elements. I created the code to find the smallest value. I just can't figure out how to move it to the front of the list. Here's my code so far:
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you know what index in the ArrayList the smallest element occupies right? So the next step is to remove it and add it at the first index in the ArrayList.
 
Dave DiRito
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again, Garrett. I was making it way harder than necessary. Now it seems so obvious.

Thank you,
Dave
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic