• Post Reply Bookmark Topic Watch Topic
  • New Topic

code output  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
void f2(List aList) {
aList.add(new Integer(42));
}
List bList = new ArrayList();
bList.add(new Integer(41));
f2(bList);
for(int n=0; n < bList.length; n++)
{
System.out.println(bList.get(n));
}

What values will this code snippets print? Why
 
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch. Please UseCodeTags when you post source code.

Did you try compiling and running the code yourself? What was the output? Can you explain the output yourself? If not, then what did you expect and how is that different from what the code actually does?
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!