Thursday, 11 December 2014

Java : Collection Framework : Vector (IndexOf method)


Click here to watch in Youtube :
https://www.youtube.com/watch?v=LGoFnHjoJ4c&list=UUhwKlOVR041tngjerWxVccw

VectorExample.java
import java.util.Vector;

/*
 *  Example of indexOf(Object o) method. 
 */
public class VectorExample
{
    public static void main( String[] args )
    {
        Vector<Integer> vector = new Vector<Integer>();

        vector.add(10);
        vector.add(20);
        vector.add(30);
        vector.add(40);
        vector.add(30);
        vector.add(50);

        System.out.println("vector  : " + vector + "\n");

        /*
         * Returns the index of the first occurrence of the specified element in
         * this vector, or -1 if this vector does not contain the element.
         */

        int indexPosition = vector.indexOf(30);

        System.out.println("indexPosition  : " + indexPosition + "\n");

    }
}

Output
vector  : [10, 20, 30, 40, 30, 50]

indexPosition  : 2

To Download VectorDemoIndexOf Project Click the below link
https://sites.google.com/site/javaee4321/java-collections/VectorDemoIndexOf.zip?attredirects=0&d=1

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • No comments:

    Post a Comment

    Google+ Followers

    Google+ Badge