Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

braintester dan

 
Dan Polak
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check yourself , do not use JVM!!!

*List<Integer> v = new ArrayList();
*List<String> v1 = new ArrayList();
*
*out.print(v == v1); //line 3
*out.println(v.equals(v1));

a) prints falsefalse
b) compile time error
c) prints truetrue
d) if 'line 3' will be removed prints true
e) prints falsetrue
f) if 'line 3' will be removed prints false
 
Xiao Song
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
b
 
Sanjeev Singh
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
b and d
Explanations : Line 3 will results in a compilation error because it is comparing collection of two different types.
equals() in the ArrayList(implemented in AbstractList) compares all the collection objects one by one and if all matches it returns true else false.In this case there is no objects at all to compare with hence will return true.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic