Win a copy of Modern frontends with htmx this week in the Spring forum!
  • 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

How do I convert these methods from Arrays to ArrayLists?

 
Ranch Hand
Posts: 105
3
Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
Marshal
Posts: 28145
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Topic has moved here: https://coderanch.com/t/673204/java/transfer-methods-Array-ArrayList#3150005
 
I don't get it. A whale wearing overalls? How does that even work? It's like a tiny ad wearing overalls.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic