Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java function - print(collection c)?

I'm trying to learn java better and I got one question.

Say I got two collections, an ArrayList and a LinkedHashSet. Is it possible to make a function like this:

void print(collection c) {
    for (object tmp:c) {
        System.out.println(tmp);
    }
}
like image 964
kristus Avatar asked Sep 11 '26 04:09

kristus


1 Answers

Watch your capitalization:

private void printCollection(Collection collection) {

   for (Object obj : collection) {
      System.out.println(obj);
   }
}
like image 150
Jason Nichols Avatar answered Sep 12 '26 17:09

Jason Nichols



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!