Home‎ > ‎Applied Core Java‎ > ‎Collection Framework‎ > ‎

Test Collection

Problem :

Step 1
- CODING
Create a text file c:\sunilos\TestCollection.java  and copy below contents.

import java.util.*;
import com.sun.org.apache.xalan.internal.xsltc.runtime.Hashtable;

/*
 * A program of collection.
 */

public class TestCollection {

    /**
     * @param args
     */
    public static void main(String[] args) {

        ArrayList v = new ArrayList();

        v.add("Manish");
        v.add("Rajnish");
        v.add("Rakesh");

        Integer i = new Integer(5);

        v.add(i);

        Integer value = (Integer) v.get(3);

        System.out.println("3 value is " + value);

        for (int j = 0; j < v.size(); j++) {
            System.out.println(j + " : " + v.get(j));
        }
    }

}


Step 2 - DEPLOYMENT
  1. Create a folder 'c:\sunilos'. 
  2. Create or copy TestCollection.java  into 'c:\sunilos' folder.
  3. Open your command prompt and go to  'c:\sunilos'
  4. Compile TestCollection.java with help of javac TestCollection.java command.  Compiled class file will be created in  .\sunilos\TestCollection.class folder
  5. Congratulations!! your Control Statement Java program is ready to serve.
Step 3 - Testing
  1. Make sure you are on Command Prompt under c:\sunilos directory
  2. Now start your Control Statements java program from command prompt with help of
    • java TestCollection command.
Output

C:\sunilos>java TestCollection
3 value is 5
0 : Manish
1 : Rajnish
2 : Rakesh
3 : 5

<<Previous
| Next>>
ċ
TestCollection.java
(1k)
nakul shukla,
Mar 19, 2009, 10:18 PM
Comments