You are on page 1of 36

Navigable Map Example

We already know that NavigableMap is similar to NavigableSet. 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. ConcurrentSkipListMap is the one of
the class which implements NavigableMap. Lets have a look at the example.

Description of program:

The following program helps you in inserting, removing and retrieving the data
from the NavigableMap. It uses the put() method to add the element. If you want
to retrieve the data at first and last position from the NavigableMap, you use the
firstEntry() and lastEntry() methods. The descendingMap() method represents
all data to the NavigableMap in descending order.

You can retrieve the nearest less than or equal to the given number and the
greatest key strictly less than the given number floorEntry() and lowerEntry()
methods. And you retrieve a key-value associated with the least key strictly
greater than the given key, you use the higherEntry() method. The
pollFirstEntry() method removes the first data from the NavigableMap and
pollLastEntry() method also removes the data at the last position from the
NavigableMap.

Here is the code of program:

import java.util.*;
import java.util.concurrent.*;

public class NavigableMapExample{


public static void main(String[] args) {
System.out.println("Navigable Map Example!\n");
NavigableMap <Integer, String>navMap = new
ConcurrentSkipListMap<Integer, String>();
navMap.put(1, "January");
navMap.put(2, "February");
navMap.put(3, "March");
navMap.put(4, "April");
navMap.put(5, "May");
navMap.put(6, "June");
navMap.put(7, "July");
navMap.put(8, "August");
navMap.put(9, "September");
navMap.put(10, "October");
navMap.put(11, "November");
navMap.put(12, "December");
//Displaying all data
System.out.println("Data in the navigable map: " +
navMap.descendingMap()+"\n");
//Retrieving first data
System.out.print("First data: " + navMap.firstEntry()+"\n");
//Retrieving last data
System.out.print("Last data: " + navMap.lastEntry()+"\n\n");
//Retrieving the nreatest less than or equal to the given key
System.out.print("Nearest less than or equal to the given key: "
+ navMap.floorEntry(5)+"\n");
//Retrieving the greatest key strictly less than the given key
System.out.println("Retrieving the greatest key strictly less than
the given key: " + navMap.lowerEntry(3));
//Retrieving a key-value associated with the least key
strictly greater than the given key
System.out.println("Retriving data from navigable map greter than
the given key: " + navMap.higherEntry(5)+"\n");
//Removing first
System.out.println("Removing First: " + navMap.pollFirstEntry());
//Removing last
System.out.println("Removing Last: " + navMap.pollLastEntry()+"\n");
//Displaying all data
System.out.println("Now data: " + navMap.descendingMap());
}
}

Download this example.

Output of program:

C:\vinod\collection>javac NavigableMapExample.java

C:\vinod\collection>java NavigableMapExample
Navigable Map Example!

Data in the navigable map: {12=December, 11=November,


10=October, 9=September, 8
=August, 7=July, 6=June, 5=May, 4=April, 3=March,
2=February, 1=January}

First data: 1=January


Last data: 12=December

Nearest less than or equal to the given key: 5=May


Retrieving the greatest key strictly less than the given key:
2=February
Retriving data from navigable map greter than the given key:
6=June

Removing First: 1=January


Removing Last: 12=December
Now data: {11=November, 10=October, 9=September,
8=August, 7=July, 6=June, 5=May
, 4=April, 3=March, 2=February}

C:\vinod\collection>

Related Tags for Navigable Map Example:


c, ant, data, insert, io, map, methods, help, method, order, vi, position, element, if,
ie, add, program, to, ram, avi, pos, ast, e, it, last, des, put, use, trie, from, first,
ce, in, as, m, nt, ps, tr, wan, os, osi, dd, osi, os, ad, es, retrieve, em, end, entry,
all, me, pro, try, s, at, moving, ir, ll, nav, pre, follow, and, removing, repr, rt, vin,
want, wing, uses, sce, s, s, ri, rd, th, av, st, ab, abl, ap, ending, ga, pr, mov, nd,
ods, on, om, ogr, ol, o

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. With the help of NavigableSet methods its just a method call to get the result. It is used
to return the closest matches of elements for the given elements in the collection.

Description of program:

Inserting the data in the NavigableSet by the add() method. The NavigableSet
provides the facility to getting the data in both orders: ascending and descending
orders. The descendingSet() method returns the data from the NavigableSet in
descending order. If you want to get the data in ascending order must be used an
iterator. An iterator stores the data as a index and the hasNext() method returns
'true' until, the next() method returns the element in ascending order.

Here, you remove the element from the NavigableSet at first and last position,
you use the pollFirst() and pollLast() methods. Sometimes, you want to get the
less and greater than or equal to the given element by using the floor() and
ceiling() methods. For getting the all elements of the NavigableSet that is greater
than or equal to the given element by the tailSet() method and less than or equal
to the given element of the NavigableSet by the headSet() method.

Here is the code of program:


import java.util.*;
import java.util.concurrent.*;

public class NavigableSetExample{


public static void main(String[] args) {
System.out.println("Navigable set Example!\n");
NavigableSet <Integer>nSet = new ConcurrentSkipListSet<Integer>();
nSet.add(10);
nSet.add(20);
nSet.add(50);
nSet.add(30);
nSet.add(100);
nSet.add(80);
// Returns an iterator over the elements in navigable set,
in ascending order.
Iterator iterator = nSet.iterator();
System.out.print("Ascending order navigable set: ");
//Ascending order list
while (iterator.hasNext()){
System.out.print(iterator.next() + " ");
}
System.out.println();
//Descending order list
System.out.println("Descending order navigable set: " +
nSet.descendingSet() + "\n");
//Greater than or equal to the given element
System.out.println("Least element in Navigable set greater than
or equal to 35: " + nSet.ceiling(35));
//Less than or equal to the given element
System.out.println("Greatest element in Navigable set less than
or equal to 35: " + nSet.floor(35) + "\n");
//Viewing the portion of navigable set whose elements are
strictly less than the given element
System.out.println("Navigable set whose elements are strictly
less than '40': " + nSet.headSet(40));
//Viewing the portion of navigable set whose elements are
greater than or equal to the given element
System.out.println("Navigable set whose elements are greater
than or equal to '40': " + nSet.tailSet(40) + "\n");
//Removing first element from navigable set
System.out.println("Remove element: "+nSet.pollFirst());
//After removing the first element, now get navigable set
System.out.println("Now navigable set: " + nSet.descendingSet() + "\
n");
//Removing last element from navigable set
System.out.println("Remove element: " + nSet.pollLast());
//After removing the last element, now get navigable set
System.out.println("Now navigable set: " + nSet.descendingSet());
}
}

Download this Example.

Output of this program


C:\vinod\collection>javac NavigableSetExample.java

C:\vinod\collection>java NavigableSetExample
Navigable set Example!

Ascending order navigable set: 10 20 30 50 80 100


Descending order navigable set: [100, 80, 50, 30,
20, 10]

Least element in Navigable set greater than or equal


to 35: 50
Greatest element in Navigable set less than or equal
to 35: 30

Navigable set whose elements are strictly less than


'40': [10, 20, 30]
Navigable set whose elements are greater than or
equal to '40': [50, 80, 100]

Remove element: 10
Now navigable set: [100, 80, 50, 30, 20]

Remove element: 100


Now navigable set: [80, 50, 30, 20]

C:\vinod\collection>

Related Tags for Navigable Set Example:


c, ide, data, insert, method, get, order, vi, return, id, set, add, to, cil, avi, ci, bot,
e, il, it, des, li, from, ce, in, as, m, dd, ad, es, end, me, pro, s, urn, at, nav, and,
ascending, rt, tt, sce, s, s, rd, th, av, ab, abl, ending, ga, pr, nd, om, o

HashSet Example

In this section we are discussing HashSet with example code that shows the
methods to add, remove and iterate the values of collection. A HashSet is a collection
set that neither allows duplicate elements nor order or position its elements.

Description of program:

In the following code segment we are performing various operations on HashSet


collection. We have explained the steps to add, remove, and test the elements of the
collection. Keys are used to put and get values. We can also execute this code on a Vector
by changing the HashSet declaration and constructor to a Vector as it supports the
collection interface.
To insert an element in the HashSet collection add() method is used. The size() method
helps you in getting the size of the collection. If you want to delete any element, use the
remove() method which takes index as parameter. In order to remove all data from the
HashSet use clear() method. When the HashSet is empty, our program checks for it and
displays a message "Collection is empty". If the collection is not empty then program
displays the size of HashSet.

Here is the code of program:

import java.util.*;

public class CollectionTest {


public static void main(String [] args) {
System.out.println( "Collection Example!\n" );
int size;
// Create a collection
HashSet <String>collection = new HashSet <String>();
String str1 = "Yellow", str2 = "White", str3 = "Green", str4 = "Blue
";
Iterator iterator;
//Adding data in the collection
collection.add(str1);
collection.add(str2);
collection.add(str3);
collection.add(str4);
System.out.print("Collection data: ");
//Create a iterator
iterator = collection.iterator();
while (iterator.hasNext()){
System.out.print(iterator.next() + " ");
}
System.out.println();
// Get size of a collection
size = collection.size();
if (collection.isEmpty()){
System.out.println("Collection is empty");
}
else{
System.out.println( "Collection size: " + size);
}
System.out.println();
// Remove specific data
collection.remove(str2);
System.out.println("After removing [" + str2 + "]\n");
System.out.print("Now collection data: ");
iterator = collection.iterator();
while (iterator.hasNext()){
System.out.print(iterator.next() + " ");
}
System.out.println();
size = collection.size();
System.out.println("Collection size: " + size + "\n");
//Collection empty
collection.clear();
size = collection.size();
if (collection.isEmpty()){
System.out.println("Collection is empty");
}
else{
System.out.println( "Collection size: " + size);
}
}
}

Download this example.

Output of this program:

C:\vinod\collection>javac
CollectionTest.java

C:\vinod\collection>java
CollectionTest
Collection Example!

Collection data: Blue White


Green Yellow
Collection size: 4

After removing [White]

Now collection data: Blue


Green Yellow
Collection size: 3

Collection is empty

C:\vinod\collection>

Related Tags for HashSet Example:


c, orm, form, hash, io, sed, get, test, remove, order, collection, key, value, rmi,
opera, ai, keys, set, position, element, move, elements, for, add, hashset, values,
to, pos, ws, sh, e, it, eps, li, put, var, use, pe, in, no, rm, operations, as, m, nt,
ps, min, os, osi, ca, dd, min, osi, os, operation, ad, es, step, em, all, me, cat,
explain, s, col, at, ratio, k, is, ha, ll, collect, follow, du, and, ar, cod, code, collect,
segment, xp, wing, va, various, s, s, ri, rd, th, steps, av, st, ati, alu, hat, either,
ica, ica, pl, plai, mov, mi, nd, ode, on, ol, o, nor

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. The code
below is similar to the previous example, but it performs many List operations. Lets
discuss the example code.

Description of program:

This program helps you in storing the large amount of data as a collection. The
LinkedList is a part of collection that constructs a list containing the elements of
the specified collection. Iterator methods returns the values in the order in which
they are stored.

If you want to insert the data in the linkedList then use add() method. The
hasNext() method returns true if the iterator contains more elements and the
next() method returns the next element in the iteration. To insert and remove the
data at first, last and specified position in the linkedList, you use the addFirst(),
addLast(), add(), removeFirst(), removeLast() and remove() methods. To
retrieve the element with respect to a specified position use the getFirst(),
getLast() and get() methods.

Here is the code of program:

import java.util.*;

public class LinkedListExample{


public static void main(String[] args) {
System.out.println("Linked List Example!");
LinkedList <Integer>list = new LinkedList<Integer>();
int num1 = 11, num2 = 22, num3 = 33, num4 = 44;
int size;
Iterator iterator;
//Adding data in the list
list.add(num1);
list.add(num2);
list.add(num3);
list.add(num4);
size = list.size();
System.out.print( "Linked list data: ");
//Create a iterator
iterator = list.iterator();
while (iterator.hasNext()){
System.out.print(iterator.next()+" ");
}
System.out.println();
//Check list empty or not
if (list.isEmpty()){
System.out.println("Linked list is empty");
}
else{
System.out.println( "Linked list size: " + size);
}
System.out.println("Adding data at 1st location: 55");
//Adding first
list.addFirst(55);
System.out.print("Now the list contain: ");
iterator = list.iterator();
while (iterator.hasNext()){
System.out.print(iterator.next()+" ");
}
System.out.println();
System.out.println("Now the size of list: " + list.size());
System.out.println("Adding data at last location: 66");
//Adding last or append
list.addLast(66);
System.out.print("Now the list contain: ");
iterator = list.iterator();
while (iterator.hasNext()){
System.out.print(iterator.next()+" ");
}
System.out.println();
System.out.println("Now the size of list: " + list.size());
System.out.println("Adding data at 3rd location: 55");
//Adding data at 3rd position
list.add(2,99);
System.out.print("Now the list contain: ");
iterator = list.iterator();
while (iterator.hasNext()){
System.out.print(iterator.next()+" ");
}
System.out.println();
System.out.println("Now the size of list: " + list.size());
//Retrieve first data
System.out.println("First data: " + list.getFirst());
//Retrieve lst data
System.out.println("Last data: " + list.getLast());
//Retrieve specific data
System.out.println("Data at 4th position: " + list.get(3));
//Remove first
int first = list.removeFirst();
System.out.println("Data removed from 1st location: " + first);
System.out.print("Now the list contain: ");
iterator = list.iterator();
//After removing data
while (iterator.hasNext()){
System.out.print(iterator.next()+" ");
}
System.out.println();
System.out.println("Now the size of list: " + list.size());
//Remove last
int last = list.removeLast();
System.out.println("Data removed from last location: " + last);
System.out.print("Now the list contain: ");
iterator = list.iterator();
//After removing data
while (iterator.hasNext()){
System.out.print(iterator.next()+" ");
}
System.out.println();
System.out.println("Now the size of list: " + list.size());
//Remove 2nd data
int second = list.remove(1);
System.out.println("Data removed from 2nd location: " + second);
System.out.print("Now the list contain: ");
iterator = list.iterator();
//After removing data
while (iterator.hasNext()){
System.out.print(iterator.next()+" ");
}
System.out.println();
System.out.println("Now the size of list: " + list.size());
//Remove all
list.clear();
if (list.isEmpty()){
System.out.println("Linked list is empty");
}
else{
System.out.println( "Linked list size: " + size);
}
}
}

Download this example.

Output of program:

C:\vinod\collection>javac
LinkedListExample.java

C:\vinod\collection>java
LinkedListExample
Linked List Example!
Linked list data: 11 22 33 44
Linked list size: 4
Adding data at 1st location: 55
Now the list contain: 55 11 22 33
44
Now the size of list: 5
Adding data at last location: 66
Now the list contain: 55 11 22 33
44 66
Now the size of list: 6
Adding data at 3rd location: 55
Now the list contain: 55 11 99 22
33 44 66
Now the size of list: 7
First data: 55
Last data: 66
Data at 4th position: 22
Data removed from 1st location:
55
Now the list contain: 11 99 22 33
44 66
Now the size of list: 6
Data removed from last location:
66
Now the list contain: 11 99 22 33
44
Now the size of list: 5
Data removed from 2nd location:
99
Now the list contain: 11 22 33 44
Now the size of list: 4
Linked list is empty

C:\vinod\collection>

Related Tags for Linked List Example:


c, list, data, io, methods, iterator, struct, help, method, link, const, order,
collection, value, return, this, ai, element, elements, large, if, ie, mount, program,
values, to, ini, ram, structs, store, ci, e, it, li, pe, art, in, part, as, m, nt, par, ps,
tr, linked, es, spec, em, me, pro, storing, stored, tor, which, s, urn, sp, col, at, k,
is, ink, ha, ll, collect, ar, collect, cons, str, rt, va, s, s, ri, ring, rd, th, st, arge,
alu, hat, cts, pr, ods, on, ogr, ol, o

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. To retrieve the keys and values use keySet() and
values() method respectively.

This program shows the data elements left after removing the particular element by specifying its
key. Using the Iterator interface methods, we can traverse a collection from start to finish and
safely remove elements from the underlying Collection.

Here is the code of program:

import java.util.*;

public class TreeMapExample{


public static void main(String[] args) {
System.out.println("Tree Map Example!\n");
TreeMap <Integer, String>tMap = new TreeMap<Integer, String>();
//Addding data to a tree map
tMap.put(1, "Sunday");
tMap.put(2, "Monday");
tMap.put(3, "Tuesday");
tMap.put(4, "Wednesday");
tMap.put(5, "Thursday");
tMap.put(6, "Friday");
tMap.put(7, "Saturday");
//Rerieving all keys
System.out.println("Keys of tree map: " + tMap.keySet());
//Rerieving all values
System.out.println("Values of tree map: " + tMap.values());
//Rerieving the value from key with key number 5
System.out.println("Key: 5 value: " + tMap.get(5)+ "\n");
//Rerieving the First key and its value
System.out.println("First key: " + tMap.firstKey() + " Value: "
+ tMap.get(tMap.firstKey()) + "\n");
//Rerieving the Last key and value
System.out.println("Last key: " + tMap.lastKey() + " Value: "
+ tMap.get(tMap.lastKey()) + "\n");
//Removing the first key and value
System.out.println("Removing first data: "
+ tMap.remove(tMap.firstKey()));
System.out.println("Now the tree map Keys: " + tMap.keySet());
System.out.println("Now the tree map contain: "
+ tMap.values() + "\n");
//Removing the last key and value
System.out.println("Removing last data: "
+ tMap.remove(tMap.lastKey()));
System.out.println("Now the tree map Keys: " + tMap.keySet());
System.out.println("Now the tree map contain: " + tMap.values());
}
}
Download this example.

Output of this program:

C:\vinod\collection>javac TreeMapExample.java

C:\vinod\collection>java TreeMapExample
Tree Map Example!

Keys of tree map: [1, 2, 3, 4, 5, 6, 7]


Values of tree map: [Sunday, Monday, Tuesday, Wednesday,
Thursday, Friday, Saturday]
Key: 5 value: Thursday

First key: 1 Value: Sunday

Last key: 7 Value: Saturday

Removing first data: Sunday


Now the tree map Keys: [2, 3, 4, 5, 6, 7]
Now the tree map contain: [Monday, Tuesday, Wednesday,
Thursday, Friday, Saturday]

Removing last data: Saturday


Now the tree map Keys: [2, 3, 4, 5, 6]
Now the tree map contain: [Monday, Tuesday, Wednesday,
Thursday, Friday]

C:\vinod\collection>

Related Tags for Tree Map Example:


c, data, method, sed, vi, key, value, this, keys, set, element, elements, show, if, ie,
example, program, values, to, ram, exam, ci, ws, sh, e, it, use, trie, ul, pe, art, left,
in, part, m, nt, par, tr, after, es, spec, retrieve, em, icu, me, how, pro, xa, xamp, s,
respect, sp, esp, at, moving, k, is, ha, iv, mpl, and, ar, removing, rt, vin, va, s, s,
ri, th, sho, av, alu, af, ple, pl, pr, mov, nd, ogr, o

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. To get the
size of TreeSet collection size() method is used. Our TreeSet collection contains 4 elements and
the size of the TreeSet can be determine by calling size() method.

Similarly, we have used first() and last() to retrieve first and last element present in the
TreeSet. Program also shows the method to remove the element and then display the remaining
elements. To remove all data from the TreeSet, use the clear() method. To determine whether
TreeSet is empty or not use isEmpty() method. If the TreeSet is empty, it displays the message
"Tree set is empty." otherwise it displays the size of TreeSet.

Here is the code of program:

import java.util.*;

public class TreeSetExample{


public static void main(String[] args) {
System.out.println("Tree Set Example!\n");
TreeSet <Integer>tree = new TreeSet<Integer>();
tree.add(12);
tree.add(23);
tree.add(34);
tree.add(45);
Iterator iterator;
iterator = tree.iterator();
System.out.print("Tree set data: ");
//Displaying the Tree set data
while (iterator.hasNext()){
System.out.print(iterator.next() + " ");
}
System.out.println();
//Check impty or not
if (tree.isEmpty()){
System.out.print("Tree Set is empty.");
}
else{
System.out.println("Tree Set size: " + tree.size());
}
//Retrieve first data from tree set
System.out.println("First data: " + tree.first());
//Retrieve last data from tree set
System.out.println("Last data: " + tree.last());
if (tree.remove(30)){
System.out.println("Data is removed from tree set");
}
else{
System.out.println("Data doesn't exist!");
}
System.out.print("Now the tree set contain: ");
iterator = tree.iterator();
//Displaying the Tree set data
while (iterator.hasNext()){
System.out.print(iterator.next() + " ");
}
System.out.println();
System.out.println("Now the size of tree set: " + tree.size());
//Remove all
tree.clear();
if (tree.isEmpty()){
System.out.print("Tree Set is empty.");
}
else{
System.out.println("Tree Set size: " + tree.size());
}
}
}

Download this example.

Output of this program:

C:\vinod\collection>javac
TreeSetExample.java

C:\vinod\collection>java
TreeSetExample
Tree Set Example!

Tree set data: 12 23 34 45


Tree Set size: 4
First data: 12
Last data: 45
Data doesn't exist!
Now the tree set contain: 12 23 34
45
Now the size of tree set: 4
Tree Set is empty.

C:\vinod\collection>

Related Tags for Tree Set Example:


c, tree, io, size, method, sed, display, remove, collection, rmi, ai, set, element,
move, elements, show, ie, call, program, to, ini, ram, contains, ast, ws, sh, e, il,
main, last, ls, calling, can, li, spl, use, trie, im, first, in, rm, cal, as, m, nt, play, tr,
min, ca, min, isp, es, retrieve, em, all, me, how, pro, similar, trees, s, term, sp, so,
ee, col, is, ir, ha, ll, collect, pre, and, ar, collect, sim, treeset, z, s, s, ri, th, sho,
av, st, disp, eterm, eterm, lso, pl, pr, mov, mi, nd, on, ogr, ol, o

Collections Framework

Java provides the Collections Framework. In the Collection Framework, a


collection represents the group of the objects. And a collection framework is the
unified architecture that represent and manipulate collections. The collection
framework provides a standard common programming interface to many of the
most common abstraction without burdening the programmer with many
procedures and interfaces. It provides a system for organizing and handling
collections. This framework is based on:
 Interfaces that categorize common collection types.
 Classes which proves implementations of the Interfaces.
 Algorithms which proves data and behaviors need when using collections
i.e. search, sort, iterate etc.

Following is the hierarchical representation for the relationship of all four


interfaces of the collection framework which illustrates the whole implementation
of the framework.

During the designing of a software (application) it need to be remember the


following relationship of the four basic interfaces of the framework are as follows:

 The Collection interface which is the collection of objects. That permits the
duplication of the value or objects.
 Set is the interface of the collections framework which extends the
Collection but forbids duplicates.
 An another interface is the List which also extends the Collection. It allows
the duplicates objects on different position because it introduces the
positional indexing.
 And Map is also a interface of the collection framework which extends
neither Set nor Collection.

Some interfaces and classes of the collection framework are as follows:

INTERFACES CLASSES
Collection Interface HashSet Class
Iterator Interface TreeSet Class
Set Interface ArrayList Class
List Interface LinkedList Class
ListIterator Interface HashMap Class
Map Interface TreeMap Class
SortedSet Interface Vector Class
SortedMap Interface Stack Class

Every interfaces and classes are explained next in the roseidia.net java tutorial one
by one in the various examples.

Advantage of the Collections Framework:

The collections framework offers developers the following benefits:

 It increases the readability of your collections by providing a standard set


of interfaces which has to be used by many programmers in different
applications.
 It makes your code more flexible. You can make the code flexible by using
many interfaces and classes of the collection framework.
 It offers many specific implementations of the interfaces. It allows you to
choose the collection that is most fitting and which offers the highest
performance for your purposes.

Interfaces of the collections framework are very easy to use. These interfaces
can be transparently substituted to increase the developed application
performance.

Related Tags for Collections Framework:


java, c, programming, architecture, com, ide, collections, interface, framework,
script, object, io, objects, interfaces, ip, vi, collection, trac, abstraction, int, id,
action, package, group, abstract, programmer, frame, if, ie, with, work, program, to,
standard, ram, proc, description, e, il, it, des, procedure, bstr, ul, man, ce, in,
architect, sta, m, nt, out, tr, min, os, min, os, j, nda, procedures, pack, arc, ace,
es, faces, without, common, age, rc, me, obj, pro, ack, s, col, bst, at, any, pac,
rac, late, k, hit, is, ha, ll, collect, pre, du, and, ar, act, collect, str, repr, util, va,
uti, scr, s, s, roc, ri, rip, rd, th, av, st, chi, ab, hat, cts, ework, face, fram, many,
je, pr, most, mi, nd, on, om, ogr, ol, o

n this section, you will learn how to implement the queue.


Implement the Queue in Java

In this section, you will learn how to implement the queue. A queue holds a collection of data or
elements and follows the FIFO ( First In First Out) rule. The FIFO that means which data added
first in the list, only that element can be removed or retrieved first from the list. In other sense,
You can remove or perform operation on that data which had been added first in the Collection
(list). Whenever you need to remove the last added element then you must remove all these
elements which are entered before the certain element.

The given program implements a queue. It takes all elements as input by user. These values are
added to the list and shows first, last and the rest elements present in the list separately. Some
methods and APIs are explained below which have been used in the program for the certain
purposes:

LinkedList<Integer>():
This is the constructor of the LinkedList class. This class is used by importing
the java.util.*; package. This constructor is used for constructing an empty list. It can contain
integer types data in the given program because in the declaration of the LinkedList class type
checking has been used. This is an implementation of the List interface of the Collections
Framework. The LinkeedList class provides inserting and deleting the data to/from the list.

removeFirst():
Above method removes and returns the first element of the list.

removeLast():
Above method removes and returns the last element of the list.

list.isEmpty():
This method checks whether the list is empty or not.

remove():
This method used to remove the elements in the list in a specified sequence.

Here is the code of program:


import java.io.*;
import java.util.*;

public class QueueImplement{


LinkedList<Integer> list;
String str;
int num;
public static void main(String[] args){
QueueImplement q = new QueueImplement();
}
public QueueImplement(){
try{
list = new LinkedList<Integer>();
InputStreamReader ir = new InputStreamReader(System.in);
BufferedReader bf = new BufferedReader(ir);
System.out.println("Enter number of elements : ");
str = bf.readLine();
if((num = Integer.parseInt(str)) == 0){
System.out.println("You have entered either zero/null.");
System.exit(0);
}
else{
System.out.println("Enter elements : ");
for(int i = 0; i < num; i++){
str = bf.readLine();
int n = Integer.parseInt(str);
list.add(n);
}
}
System.out.println("First element :" + list.removeFirst());
System.out.println("Last element :" + list.removeLast());
System.out.println("Rest elements in the list :");
while(!list.isEmpty()){
System.out.print(list.remove() + "\t");
}
}
catch(IOException e){
System.out.println(e.getMessage() + " is not a legal entry.");
System.exit(0);
}
}
}
Download this example
In this Example you will learn you will learn how to iterate collection in java.

Collection Iterate Example

In this section, you will get the detailed explanation about the hasNext() method of
interface Iterator. We are going to use hasNext() method of interface Iterator in Java. The
description of the code is given below for the usage of the method.

Description of the code:

Here, you will get to know about the hasNext() method through the following java program. True
is return by this method in case the iteration has more elements. This means that if the iteration
has more elements then the hasNext() method will return true rather than throwing an exception.

In the program code given below, we have taken a string of elements. We have converted this
string of elements into a list of array and then we have applied the hasNext() method which
returns true because there are more elements in the list. Hence we get the following output.

Here is the code of program:


import java.util.*;

public class hasNext{


public static void main (String args[]) {
boolean b;
String elements[] = {"Blue", "Grey", "Teal"};
Set s = new HashSet(Arrays.asList(elements));
Iterator i = s.iterator();
if (b = i.hasNext()){
System.out.println(b);
}
}
}

Output of the program:


C:\unique>javac
hasNext.java

C:\unique>java
hasNext
true

C:\unique>

Download this example.


Here is the illustration for the conversion from the collection to an array. In this section,
you will learn how to do this.
Converting Collection to an Array

Here is the illustration for the conversion from the collection to an array. In this section, you will
learn how to do this. The given example gives you a brief introduction for convert collection to an
array without losing any data or element present in the collection.

This program creates a List. List is a type of collection that contains a ordered list of elements.
This list (collection) is converted into an array. Length of the created array is defined by the
system according to the number of elements in the list. Each and every subscripts hold separate
element.

Code Description:

Here is the explanation of some methods and APIs whatever has been used in the program:

List:
List is the class of the java.util package which creates a list for containing some elements. In this
program, this class is used with the type checking.

add():
Above method adds elements to the list. This method holds string which is the element name.

List.toArray(new String[0]):
Above code converts a list into a String Array. This method returns a string array which length is
fixed according to the number of elements present in the list. Overall this code converts collection
to an array.

Here is the code of the program:


import java.util.*;

public class CollectionToArray{


public static void main(String[] args){
List<String> list = new ArrayList<String>();
list.add("This ");
list.add("is ");
list.add("a ");
list.add("good ");
list.add("boy.");
String[] s1 = list.toArray(new String[0]); //Collection to array
for(int i = 0; i < s1.length; ++i){
String contents = s1[i];
System.out.print(contents);
}
}
}

Here is the illustration for the conversion from the an array to a collection. In this section, you will learn how h

Converting an Array to a Collection

Here is the illustration for the conversion from the an array to a collection. In this section, you will learn how how to do

This program creates an array, that contains all the elements entered by you. This array is converted into a list (collecti

Code Description:

Arrays.asList(name):
Above code converts an array to a collection. This method takes the name of the array as a parameter which has to be

for(String li: list):


This is the for-each loop. There are two arguments mentioned in the loop. In which, first is the String type variable li an
variable li.

Here is the code of the program:

import java.util.*;
import java.io.*;

public class ArrayToCollection{


public static void main(String args[]) throws IOException{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.print("How many elements you want to add to the array: ");
int n = Integer.parseInt(in.readLine());
String[] name = new String[n];
for(int i = 0; i < n; i++){
name[i] = in.readLine();
}
List<String> list = Arrays.asList(name); //Array to Collection
for(String li: list){
String str = li;
System.out.print(str + " ");
}
}
}

In this section, you will learn how to implement a stack in Java.

Implementing a Stack in Java

In this section, you will learn how to implement a stack in Java. A Stack is like a bucket in which
you can put elements one-by-one in sequence and retrieve elements from the bucket according
to the sequence of the last entered element. Stack is a collection of data and follows
the LIFO (Last in, first out) rule that mean you can insert the elements one-by-one in sequence
and the last inserted element can be retrieved at once from the bucket. Elements are inserted
and retrieved to/from the stack through the push() and pop() method.

This program implements a stack and follows the LIFO rule. It asks you for the number of
elements which have to be entered in the stack and then it takes elements for insertion in the
stack. All the elements present in the stack are shown from the last inserted element to the first
inserted element.

Stack<Integer>():
Above constructor of the Stack class creates a empty stack which holds the integer type value
which is mention with the creation of stack. The Stack class extends the Vector class and both
classes are implemented from the java.util.*; package.

Stack.push(Object obj):
Above method is used to insert or push the data or element in the stack. It takes an object like:
data or elements and push its onto the top of the stack.

Stack.pop():
This is the method to removes the objects like: data or elements at the top positions of stack.

Here is the code of program:


import java.io.*;
import java.util.*;

public class StackImplement{


Stack<Integer> stack;
String str;
int num, n;
public static void main(String[] args){
StackImplement q = new StackImplement();
}
public StackImplement(){
try{
stack = new Stack<Integer>();
InputStreamReader ir = new InputStreamReader(System.in);
BufferedReader bf = new BufferedReader(ir);
System.out.print("Enter number of elements : ");
str = bf.readLine();
num = Integer.parseInt(str);
for(int i = 1; i <= num; i++){
System.out.print("Enter elements : ");
str = bf.readLine();
n = Integer.parseInt(str);
stack.push(n);
}
}
catch(IOException e){}
System.out.print("Retrieved elements from the stack : ");
while (!stack.empty()){
System.out.print(stack.pop() + " ");
}
}
}
his section gives you the best illustration for sorting elements of a Collection.

Sorting elements of a Collection

This section gives you the best illustration for sorting elements of a Collection. You can see how
to sort all elements of a Collection in ascending or descending order.

In this section, the given program sorts all the elements of a Collection in ascending order. If your
text starts with the Upper case letter then the text comes first that mean the uppercase letter is
less priority than lowercase letter.

Code Description:
This program creates an string type array and takes some text as input from the user for the
created array. Array with elements are assigned to the List (Collection) and then all the elements
of the list are arranged in the ascending order.

Collections.sort(list):
Above method sorts all the elements of the specified Collection. List name which elements have
to be sorted is passed through the method as a parameter. This method sorts elements in
ascending order by default.

Here is the code of the program:


import java.util.*;
import java.io.*;

public class SortingCollection{


public static void main(String[] args) throws IOException{
int n = 0;
BufferedReader in = new BufferedReader(new InputStreamReader(System.i
System.out.print("How many elements you want to enter in the list : "
try{
n = Integer.parseInt(in.readLine());
}
catch(NumberFormatException ne){
System.out.println(ne.getMessage() + " is not a legal entry.");
System.out.println("Please enter a numeric value.");
System.exit(1);
}
String[] names = new String[n];
System.out.println("Please enter some names : ");
for(int i = 0; i < n; i++){
names[i] = in.readLine();
}

List<String> list = Arrays.asList(names);


Collections.sort(list);
System.out.print("Elements of the list in sorted order : " + list);
}
}
Download this example.

This section explains the implementation of the hash table. What is the hash table and
how to create that?

Creating a Hash Table : Java Util


This section explains the implementation of the hash table. What is the hash table and how to
create that? Hash Table holds the records according to the unique key value. It stores the non-
contiguous key for several values. Hash Table is created using an algorithm (hashing function) to
store the key and value regarding to the key in the hash bucket. If you want to store the value for
the new key and if that key is already exists in the hash bucket then the situation known
as collision occurs which is the problem in the hash table i.e. maintained by the hashing
function. The drawback is that hash tables require a little bit more memory, and that you can not
use the normal list procedures for working with them.

This program simply asks you for the number of entries which have to entered into the hash table
and takes one-by-one key and it's value as input. It shows all the elements with the separate key.

Code Description:

Hashtable<Integer, String> hashTable = new Hashtable<Integer, String>():


Above code creates the instance of the Hashtable class. This code is using the type checking of
the elements which will be held by the hash table.

hashTable.put(key, in.readLine()):
Above method puts the values in the hash table regarding to the unique key. This method takes
two arguments in which, one is the key and another one is the value for the separate key.

Map<Integer, String> map = new TreeMap<Integer, String>(hashTable):


Above code creates an instance of the TreeMap for the hash table which name is passed through
the constructor of the TreeMap class. This code creates the Map with the help of the instance of
the TreeMap class. This map has been created in the program for showing several values and it's
separate key present in the hash table. This code has used the type checking.

Here is the code of the program:


import java.util.*;
import java.io.*;

public class HashTable{


public static void main(String[] args) throws IOException{
int key;
try{
BufferedReader in = new BufferedReader(new InputStreamReader(System
System.out.print("How many elements you want to enter to the hash t
int n = Integer.parseInt(in.readLine());
Hashtable<Integer, String> hashTable = new Hashtable<Integer, Strin
for(int i = 0; i < n; i++){
System.out.print("Enter key for the hash table : ");
key = Integer.parseInt(in.readLine());
System.out.print("Enter value for the key : ");
hashTable.put(key, in.readLine());
}
Map<Integer, String> map = new TreeMap<Integer, String>(hashTable);
System.out.println(map);
}
catch(NumberFormatException ne){
System.out.println(ne.getMessage() + " is not a legal value.");
System.out.println("Please enter a numeric value.");
System.exit(1);
}
}
}
Download this example.

n the sorted array, searching is very easy. In this section, you will learn how to sort an
array and how to find a text in the sorted array.

Finding an Element in a Sorted Array

In the sorted array, searching is very easy. In this section, you will learn how to sort an array and
how to find a text in the sorted array. For binary search first you must sort the array and then
apply the binary search.

This section gives you a example for understanding the sorting an array an searching an
elements in the array. This example takes some inputs from the user for the array and takes a
another text for search in the array after sorting that. And it show the given text position in the
array, if text is present in the array otherwise the program shows the message : "Given word is
not available in the array." and terminate the program.

Code Description:

Arrays.sort(names):
Above method sorts all the elements present in the array. This method takes the array name as a
parameter which elements have to be sorted and it sorts elements by default in ascending order.

Arrays.binarySearch(names, in.readLine()):
Above method searches the element in the specified array in the way of binary search. This way
of searching takes more less time than the index search or the sequential search. This method
takes two arguments as follows:

 Name of the array.


 String for search in the specified array.

This method returns the positive value from 0 (zero) to length_of_array-1, if the given string is
available in the array and returned value is the position of the text in the array otherwise this
method returns the negative value that means given string is not available in the array.

Here is the code of the program:


import java.util.*;
import java.io.*;

public class FindElementFromSortedArray{


public static void main(String[] args) throws IOException{
int n = 0;
BufferedReader in = new BufferedReader(new InputStreamReader(System.i
System.out.print("How many elements you want to enter into the array
try{
n = Integer.parseInt(in.readLine());
}
catch(NumberFormatException ne){
System.out.println(ne.getMessage() + " is not a legal value.");
System.out.println("Please enter a numeric value.");
System.exit(1);
}
String[] names = new String[n];
System.out.print("Enter value for the array : ");
for(int i = 0; i < n; i++){
names[i] = in.readLine();
}
Arrays.sort(names);
System.out.println("Elements of the array in ascending order : ");
for(int i = 0; i < names.length; i++){
System.out.println(names[i]);
}
System.out.print("Enter the string for search in the array : ");
int position = Arrays.binarySearch(names, in.readLine());
if(position < 0 || position > n-1){
System.out.println("Given word is not available in the array.");
System.exit(1);
}
else{
System.out.println("\"" + names[position] + "\" is available
in the array at position " + (position + 1) +".");
}
}
}
Download this example.

This section shows the way of getting the current time of the system.

Getting the Current Time

This section shows the way of getting the current time of the system.

In this section, through the given program you can get the current time in the proper format
(Hour:Minute:Second AM/PM). This program shows the current time by using the various
methods of the Calendar class. These are explained as follows:

Code Description:

Calendar:
Date is the special instance of the time. This class helps you to convert a date format object into
the integer fields like YEAR, MONTH, HOUR, MINUTE, SECOND etc.

Calendar.get(Calendar.MINUTE):
Above method gives you the minute value from the current time and MINUTE is the predefined
field of the Calendar class which returns the integer value i.e. the minute value of the current time

Calendar.AM_PM:
Above field of the Calendar class returns the integer value 1, if the current time is in the PM
otherwise it returns 0 value which denotes the time is in the AM period.

Here is the code of the program:


import java.util.*;

public class CurrentTime{


public static void main(String[] args){
Calendar calendar = new GregorianCalendar();
String am_pm;
int hour = calendar.get(Calendar.HOUR);
int minute = calendar.get(Calendar.MINUTE);
int second = calendar.get(Calendar.SECOND);
if(calendar.get(Calendar.AM_PM) == 0)
am_pm = "AM";
else
am_pm = "PM";
System.out.println("Current Time : " + hour + ":"
+ minute + ":" + second + " " + am_pm);
}
}
Download this example.

n this section, the given program shows you how to get about all the information for the
time zones.

Getting Information of All Available Time Zones

Time Zone: Time Zone is the specified part of the earth that holds the special standard of the
time i.e. termed as local time. Usually time zone is based on the GMT (Greenwich Mean Time).
Each and every part of the earth has categorized for holding it's own time zones that had been
fixed according to the rotation of the earth on it's own base.

Most application software uses the underlying operating system for getting all information about
the time zones for setting up the time according to the appropriate time zones. Java maintains it's
own time zones database as well as the operating system database. There need to update the
java time zone database from the operating system database when it is changed.

DST (Daylight Saving Time): Daylight Saving Time is also called the summer time somewhere
in many countries. In this period the sun rises in the morning and sets in the evening one hour
later. So, the evening became one hour longer. Benefit of the period is saving energy because in
this period artificial light is less needed during the evening. To make DST work, when DST
begins, clocks have to be adjusted one hour ahead and adjusted one hour back to standard time
every autumn. Many countries maintain the DST and many do not.

Up to now, most of the United States have observed Daylight Saving Time from the first Sunday
of April at 2:00 am to the last Sunday of October at 2:00 am. In 2007, most of the U.S. will begin
Daylight Saving Time from the second Sunday of March at at 2:00 a.m. and revert to standard
time on the first Sunday in November. In the U.S., each time zone switches at a different time.

Program Result:

In this section, the given program shows you how to get about all the information for the time
zones. This program shows all time zones available in the world with the Time Zone ID, Time
Zone Nameand it's fixed GMT (India Standard Time : 5:30).
Code Description:

TimeZone:
This class is used to getting and setting the time zone. You can get the default time zone using
thegetDefault() method i.e. the time zone on where your program is running.

TimeZone.getAvailableIDs():
Above method returns a array of all time zone ids like the time zone id for the time zone of India
isAsia/Calcutta.

TimeZone.getTimeZone(id):
Above method returns the full name of the Time Zone. The time zone id, which full name has to
be found, is passed through the method as a parameter.

TimeZone.getDisplayName(TimeZone.inDaylightTime(new Date()), TimeZone.LONG):


Above code of the program represents two methods and a field of the TimeZone class these are
explained as follows:

 TimeZone.LONG:
This field of the TimeZone class returns a static integer value which is used in
thegetDisplayName() method of the class as a parameter for specifying the style of the
name of the time zone. It determines the long (full) name of the specific time zone.
Another field is theTimeZone.SHORT which determines the short name of the time zone.

 TimeZone.inDaylightTime(new Date()):
This method returns the abstract boolean type value after checking whether the given
date is in the Daylight Saving Time period or not. It returns true, if the date is in the DST
(Daylight Saving Time) otherwise false.

 TimeZone.getDisplayName(TimeZone.inDaylightTime(new Date()),
TimeZone.LONG):
This method gives you the full name of the specified time zone. This method returns
String type value which is the name of the time zone for the specified Locale.

TimeZone.getRawOffset():
Above method returns the amount of time to add UTC () to get standard time for the specified
time zone. This method returns the static integer value which is the amount of time in millisecond.
Math.abs(real_number):
This method returns the absolute number for the given number. The number, which has to
become absolute, is passed through the method as a parameter.

Here is the code of the program:


import java.util.*;

public class TimeZones{


public static void main(String[] args){
Date date = new Date();
String TimeZoneIds[] = TimeZone.getAvailableIDs();
for(int i = 0; i < TimeZoneIds.length; i++){
TimeZone tz = TimeZone.getTimeZone(TimeZoneIds[i]);
String tzName =
tz.getDisplayName(tz.inDaylightTime(date), TimeZone.LONG);
System.out.print(TimeZoneIds[i] + ": ");
// Get the number of hours from GMT
int rawOffset = tz.getRawOffset();
int hour = rawOffset / (60*60*1000);
int minute = Math.abs(rawOffset / (60*1000)) % 60;
System.out.println(tzName + " " + hour + ":" + minute);
}
}
}
Download this example.

This section shows the way of getting the current date of the system.

Getting the current date

This section shows the way of getting the current date of the system.

In this section, through the given program you can get the current date in the proper format
(Day/Month/Year). This program shows the current date by using the various methods and fields
of theCalendar class. These are explained as follows:

Code Description:

Calendar.MONTH:
This field of the Calendar class returns the static integer which is the value of the month of the
year.
Calendar.DAY:
This field returns a static integer value which is the value of the day of the month in the year.

Calendar.YEAR:
This field returns a static integer value which is the current year.

Here is the code of the program:


import java.util.*;

public class CurrentDate{


public static void main(String[] args){
Calendar cal = new GregorianCalendar();
int month = cal.get(Calendar.MONTH);
int year = cal.get(Calendar.YEAR);
int day = cal.get(Calendar.DAY_OF_MONTH);
System.out.println("Current date : "
+ day + "/" + (month + 1) + "/" + year);
}
}
Download this example.

Determining the Number of Days in a Month

This section will show the way of counting the number of days of a month in the specified year.
Following program takes the year as input through the keyboard and shows the number of days
in the February month of the mentioned year if the year is valid other it will show the error
message and terminate the program.

Code Description:

GregorianCalendar(year, Calendar.FEBRUARY, 1):


Above is the constructor of the GregorianCalendar class which create an instance for that. Year
and month are specified in the constructor to create instance for finding the number of days in
that month of the specified year. Here, the constructor takes three arguments as follows:

 First is the year.


 Second is the month (February).
 And third is the initial date value.
Calendar.getActualMaximum(Calendar.DAY_OF_MONTH):
Above method finds and returns the maximum date value in the specified month of the specific
year. It returns a integer value.

Here is the code of the program:


import java.util.*;
import java.io.*;

public class GettingDaysInMonth{


public static void main(String[] args) throws IOException{
int year = 1;
BufferedReader in = new BufferedReader(new InputStreamReader(System.i
System.out.print("Enter year : ");
try{
year = Integer.parseInt(in.readLine());
if (year < 1900 || year > 2100){
System.out.println("Please enter year greater than 1900 and less
System.exit(0);
}
}
catch(NumberFormatException ne){
System.out.print(ne.getMessage() + " is not a valid entry.");
System.out.println("Please enter a four digit number.");
System.exit(0);
}
Calendar cal = new GregorianCalendar(year, Calendar.FEBRUARY, 1);
int days = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
System.out.print("Number of days : " + days);
}
}
In this section, you will read about the jar file.

What is a JAR file in Java

JAR file is the compressed file format. You can store many files in a JAR file. JAR stands for the
Java Archive. This file format is used to distribute a set of java classes. This file helps you to
reduce the file size and collect many file in one by compressing files. Downloading the files are
become completed in very short duration of time because of reducing the file size. You can make
the jar file executable by collecting many class file of your java application in it. The jar file can
execute from the javaw (Java Web Start).
The JAR file format is based on the popular ZIP file format. Usually these file format is not only
used for archiving and distribution the files, these are also used for implementing various libraries,
components and plug-ins in java applications. Compiler and JVMs (Java Virtual Machine) can
understand and implement these formats for java application.

For mentioning the product information like vendor name, product version, date of creation of the
product and many other things related to the product are mentioned in the manifest file. Such
type of files are special which are mentioned in the jar file for making it executable for the
application. This file format is to be used for collecting auxiliary files associated with the
components.

To perform basic operations for the jar file there has to be used the Java Archive Tool (jar
tool). It is provided by the jdk (Java Development Kit). Following are some jar command
which are invoked by the jar tool:
Functions Command
creation a jar file jar cf jar-file-name file-name(s)_or_directory-
viewing contents of a jar file name
viewing contents with detail of a jar jar tf jar-file-name
file jar tvf jar-file-name
extract all the files of a jar file jar xf jar-file-name
extract specific files from the jar file jar xf jar-file-name file-name(s)_from_jar-file
update jar files jar uf jar-file-name file-name(s)_from_jar-file
running a executable packaged jar file java -jar jar-file-name
Related Tags for What is a JAR file in Java:
java, c, function, jar, fun, io, definition, this, functional, ie, unc, ini, e, it, des, section, li, init,
in, j, es, func, describe, s, is, functionality, definitions, and, ar, va, scr, s, s, ri, th, av, bes, f
in, nd, on, o

«Previous Index Next»

This section provides you to the creating a jar file through the java source code by using
the jar tool command which is provided by the JDK (Java Development Kit).

Creating a JAR file in Java

This section provides you to the creating a jar file through the java source code by using the jar
tool command which is provided by the JDK (Java Development Kit). Here, you can learn how to
use the jar command, which is used in the dos prompt, in the java source code to perform same
operations.
Following program is given for best illustration about using the dos used command in the java
source code to perform the appropriate tasks. This program has been used the jar command "jar
cf jar-file-name directory-name" in the source code to create a jar file for the given directory. You
can also specify the file name(s) to collect it into the jar file format.

Code Description:

Runtime:
Runtime is the class of java.lang.*; package of Java. This class helps application to interface with
the environment in which the java application is running.

Runtime.getRuntime():
This method gets the current runtime environment.

Runtime.exec(String[] command):
This method helps you to run the command of that environment in which your java application is
running.

Here is the code of the program:


import java.io.*;

public class CreateJar{


public static void main(String[] args) throws IOException{
if(args.length <= 0){
System.out.println("Please enter the command.");
System.exit(0);
}
else{
Runtime.getRuntime().exec(args[0] + " "
+ args[1] + " " + args[2] + " " + args[3]);
}
}
}
Download this example.

You might also like