• 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

how containsAll() works

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


hi everyone

while executing the above program when
System.out.println(l.contains(a)); executes it returns true
but when System.out.println(l.containsAll(a)); this statement executes it returns false.

how it is happening ?

can anyoone give me the idea behind the execution?
 
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Suvendu Panda wrote:System.out.println(l.contains(a)); executes it returns true
but when System.out.println(l.containsAll(a)); this statement executes it returns false.

how it is happening ?

can anyoone give me the idea behind the execution?


Your list contains 'a' but does not contain all of "I", "can", "do", "what", "I" and "want"

If that answer doesn't make sense read the javadoc for List and see what the contains and containsAll methods actually do.
 
Ranch Hand
Posts: 514
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello!

ContainsAll in list is implemeted as this :

Contains method simply calls indexOf method :

To find out more about ArrayList as well as LinkedList please cover my tutorials here.
They are about internal life of ArrayList and LinkedList.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic