• Post Reply Bookmark Topic Watch Topic
  • New Topic

How do I convert these methods from Arrays to ArrayLists?  RSS feed

 
Ranch Hand
Posts: 105
3
Chrome Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, so I have to convert my ArrayBasics class into an ArrayListBasics class. Basically, I have to change everything from and Array to ArrayList. However, I have begun to get a little bit lost. I though I was understanding how to convert all of these arrays into array lists, but I have begun to get errors when checking to make sure that my code compiles. Right now, I am getting an error in my reverse method that says  unexpected type, found variable, require value. If someone could help me work though some of the issues I am havng in converting my code, that would be great, because as of right now, I am honestly lost.  Here is my original Array code:



and here is the code I have been working on converting. I believe some of the methods work, but I am at a loss for the merge method and what I am doing wrong in the reverse method. When I had cancelled out these methods to check to see if anything else was wrong, I also found that my min method was giving an out of bounds exception error. Im sorry, I am very confused. Here is my ArrayList code I am working on:

 
Sheriff
Posts: 22844
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your min() method should be almost identical to max(), except for > versus <, shouldn't it?
 
David Vach
Ranch Hand
Posts: 105
3
Chrome Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Your min() method should be almost identical to max(), except for > versus <, shouldn't it?


Yeah, thanks for that. That helped me get my min method correct. However, after compiling without the reverse and merge methods, which I'm still not sure how to get to work, I found that my print method is only printing some of my numbers in the array. It does not print all of them. I am also not sure why my inOrder method does not work, because it is only returning true when it should be returning false false true.
 
David Vach
Ranch Hand
Posts: 105
3
Chrome Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have gotten my boolean to work for my order I believe as well as finding the min value. However, I am still having trouble finding out how to fix my reverse order and merge.
 
David Vach
Ranch Hand
Posts: 105
3
Chrome Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm also not sure how to get rid of the last comma, which I was able to do on my ArrayBasics class.
 
David Vach
Ranch Hand
Posts: 105
3
Chrome Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Topic has moved here: https://coderanch.com/t/673204/java/transfer-methods-Array-ArrayList#3150005
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!