Java Collection

Java Collection

This class serves as an handle to the underlying machine-specific structure representing an open file, an open socket, or another source or sink of bytes. This handle can be err, in or out. It is used to create a FileInputStream or FileOutputStream to contain it. It inherits methods from the class.

Some advantages of collection framework are as follows:

  • Decreases programming effort
  • Increases speed of program and quality
  • Consistent API

Various interfaces present in the collections framework are as follows:

  • equals() – Used to match two collections
  • removeIf() – Used to remove element if it matches the condition
  • spliterator() – Used to generate a spliterator over the specified elements
  • iterator() – Used to return an iterator for invoking collection
  • stream() – Used to return a sequential stream with the collection at its source
  • parallelStream() - Used to return a parallel stream with the collection at its source
  • toArray() – Used to convert collection to array

Some methods of collection interface are as follows:

  • Collection interface
  • Iterable interface
  • List interface
  • Set interface
  • Sorted Set interface
  • Queue interface
  • Map interface

Example :

import java.util.*; class TestJavaCollection1{ public static void main(String args[]){ ArrayList<String> list=new ArrayList<String>(); list.add("Knowledge2life 1"); list.add("Knowledge2life 2"); Iterator itr=list.iterator(); while(itr.hasNext()){ System.out.println(; } } }


Knowledge2life 1
Knowledge2life 2