• 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

Passing Arraylist to class

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello I want to pass one arraylist to a class but I have no idea how . the class is located to one library I made and Imported in my main class how can I make it take the values? (univeristy practical exersise)


 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

You should always use code tags, which I have added to your code, and you can see how much better it looks
Unfortunately it highlights the fact that your indentation is inconsistent, which makes the code much more difficult for you to read. Also you should use {} after if etc. For the same reason. Your variable names are not very good; you have a class called classes (should be C not c) which handles collections, and which you are calling num.
I can’t see anything wrong with the way you are passing your List, assuming that max() method takes a List<Integer> as a parameter. What you have done wrong, hoever, is
  • Put too much code in a static setting, or
  • Tried inappropriately to use an instance field.
  • I think the first error is likelier to be true.
    I prefer to initialise all instance fields in the constructor (I know some people will disagree with me), so you need to write a constructor. I also don’t like break; (again some people will disagree), so I would move the != 0 test into the loop continuation condition. Unfortunately that means writing the reading statement twice.I presume you know about boxing and unboxing, and about declaring a List<XXX> rather than ArrayList?
     
    Ranch Hand
    Posts: 62
    Netbeans IDE MySQL Database Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    ^^what he said much more eloquently than I did
     
    Campbell Ritchie
    Marshal
    Posts: 79177
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Note that I didn’t write much new code yesterday. I simply moved the old code around.
     
    Yeah. What he said. Totally. Wait. What? Sorry, I was looking at this tiny ad:
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic