Java 6.0
New Features (Collection Framework)
As the name indicates collections
is a group of objects known as its elements.
Basically it is a package of data structures that includes ArrayLists,
LinkedLists, HashSets,
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.
Introduction
to Collections API
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.
Advantages
and Disadvantages of collection Framework
In this section, you will
read the advantages and disadvantages of Java Collection
Framework.
Java
6.0 Collection Framework
Some of the new collections
APIs have been introduced in Java 6.0.
Collections
Framework Enhancement
In Collection framework, we are able to improve the
performance hashing function that is used by java.util.HashMap. It
provides some new Collection interfaces also.
Lets See How to Work With Collections Framework With the Help of Following Examples.
Navigable
Map Example
In
NavigableMap we use methods to return the key value pair
like navMap.put(1, "January"); whereas in NavigableSet
we use methods to return values.
Navigable
Set Example
In the example below we have used NavigableSet method to
sort the elements in ascending order, descending order, also to
retrieve the element which is immediately greater than or equal
to 35 etc.
HashSet
Example
In this section provides you an example to HashSet
collection frame work. A
HashSet
is a set that doesn't allow duplicate elements and doesn't order
or position its elements.
Linked
List Example
This section discusses an example to demonstrate the various
methods of List interface. We are using two classes ArrayList
and LinkedList in the example code.
Tree
Map Example
In the following example, we have used the TreeMap
method, which stores its elements in a tree and orders its
elements based on their values. Here in the example we have used
the key of the element to show the values of the element.
Tree
Set Example
In the following example, we have used the TreeSet
collection, which is similar to TreeMap that stores its
elements in a tree and maintain order of its elements based on
their values.
HelloWorld
Java Program
Simple Java Program for beginners that prints HelloWorld! on
console.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Collection of Large Number of Java Sample Programs and Tutorials
Post your Comment