Powered by Blogger.

The Collection API of Java Platform | List of Java APIs

Introduction of API:-

As the name indicates, collections is a group of objects known as its elements. Basically it is a package of data structures that includes Array Lists, Linked Lists, Hash Sets, etc. A collection is simply an object that groups multiple elements into a single unit. It is also called as a container sometimes. It is used to store, retrieve, manipulate, and communicate aggregate data. Typically, it represents data items that form a natural group and allows duplicate elements while others do not. It consists of both ordered and unordered elements. There is no direct implementation of this interface however SDK provides implementations of more specific sub interfaces like Set and List. The manipulation and passing of collections is done by this interface.

The Two "standard" constructors should be provided by all the general-purpose Collection implementation classes. These classes typically implement Collection indirectly through one of its sub interfaces.

   1. Void (no arguments) constructor which creates an empty collection.

   2. Constructor with a single argument of type Collection, which creates a new collection with the same elements as its argument.

The user can copy any collection using void constructor to produce an equivalent collection of the desired implementation type. As interfaces cannot contain constructors there is no way to enforce this convention. However all of the general-purpose Collection implementations comply this in the Java platform libraries.

The Java Collections API:

Java Collections of API (Application Programming Intreface) Consists of several interfaces, and classes that implement those interfaces, within the java.util package. It provides tools for maintaining a data container of objects. Each primitive value must be wrapped in an object of its appropriate wrapper class (Boolean, Character, Integer, Double, etc.) to maintain a collection of primitive data. It is an alternative tool to the creation of custom data structures.

You must be familiar with collections if you have worked with Java programming language. Collection implementations included Vector, Hashtable, and array are available in earlier (pre-1.2) versions of the Java platform, but those versions do not include the collections framework. Hence the new version of the Java platform contains the collections framework.

The Collection API:-

A collection is a single object representing a group of objects. The objects in the collection are called elements. Implementation of collection determine whether there is specific ordering and whether duplicates are permitted.

1. Set An unordered collection, where no duplicates are permitted.

2. List An ordered collection, where duplicates are permitted.

1  import java.util.*;
2
3  public class SetExample{
4    public static void main(String[]agrs){
5      Set set = new HashSet();
6      set.add(”One”);
7      set.add(”2nd”);
8      set.add(”3rd”);
9      set.add(new Integer(6));
10     set.add(new Float(7.7F));
11     set.add(”2nd”); // duplicate are not added
12     System.out.println(set);
13   }
14 }

1  import java.util.*;
2
3  public class ListExample{
4    public static void main(String[]agrs){
5      List list = new ArrayList();
6      list.add(”One”);
7      list.add(”2nd”);
8      list.add(”3rd”);
9      list.add(new Integer(6));
10     list.add(new Float(7.7F));
11     list.add(”2nd”); // duplicate is added
12     System.out.println(list);
13   }
14 }

Related Tags for Introduction to Collections API:

c, array, list, collections, data, hash, object, lists, io, objects, include, struct, link, collection, arraylist, structure, sets, name, package, set, element, includes, group, basic, elements, call, hashset, ical, sh, e, it, des, structures, li, in, no, cal, as, m, nt, tr, ca, linked, j, pack, cl, es, sts, em, all, age, me, obj, ack, cat, s, col, at, pac, k, inc, is, ink, ha, ll, collect, ray, ar, collect, str, s, s, th, st, hat, cts, etc, etc, indic, je, ica, ica, nd, on, ol, o.

1 comment: