Monday 15 December 2014

Java : Collection Framework : Vector (lastIndexOf Overloaded Method)


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

VectorExample.java
import java.util.Vector;

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

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

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

        /*
         * Returns the index of the last occurrence of the specified element in
         * this vector, searching backwards from index, or returns -1 if the
         * element is not found.
         */

        int indexPosition = vector.lastIndexOf(30, 5);

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

    }
}

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

indexPosition  : 4

To Download VectorDemoLastIndexOfIndex Project Click the below link
https://sites.google.com/site/javaee4321/java-collections/VectorDemoLastIndexOfIndex.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