This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Passing Arraylist to class  RSS feed

 
demeteor apo
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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)


 
Campbell Ritchie
Marshal
Posts: 55745
163
  • Mark post as helpful
  • send pies
  • 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?
     
    Phil English
    Ranch Hand
    Posts: 62
    MySQL Database Netbeans IDE Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    ^^what he said much more eloquently than I did
     
    Campbell Ritchie
    Marshal
    Posts: 55745
    163
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Note that I didn’t write much new code yesterday. I simply moved the old code around.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!