Online Java Compiler By
JavaTpoint.com
import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.concurrent.ConcurrentLinkedQueue; public class JavaCollectionSizeExample2 { public static void main(String[] args) { Collection
collection = new ConcurrentLinkedQueue
(); char i; for(i='a';i<='z';++i){ collection.add(i); } //returns the total size of the collection System.out.println("Total alphabets : "+collection.size()); System.out.println("collection : "+collection); List
list = new ArrayList
(); list.add('a'); list.add('e'); list.add('i'); list.add('o'); list.add('u'); collection.retainAll(list); // returns the size of the collection System.out.println("Number of vowels : "+collection.size()); System.out.println("Vowels : "+collection); } }
Output