Vector: indexOf(Object o) : Vector « java.util « Java by API






Vector: indexOf(Object o)

  
/*
 Output:

[A, B, C]
Contains A?: true
Where's A?: 0
Where's B from end?: 1
C



 * */

import java.util.Vector;

public class MainClass {
  static String members[] = { "A", "B", "C"};

  public static void main(String args[]) {
    Vector v = new Vector();
    for (int i = 0, n = members.length; i < n; i++) {
      v.add(members[i]);
    }
    System.out.println(v);
    System.out.println("Contains A?: " + v.contains("A"));
    System.out.println("Where's A?: " + v.indexOf("A"));
    System.out.println("Where's B from end?: " + v.lastIndexOf("B"));
    int index = 0;
    int length = v.size();
    while ((index < length) && (index >= 0)) {
      index = v.indexOf("C", index);
      if (index != -1) {
        System.out.println(v.get(index));
        index++;
      }
    }
  }
}
           
         
    
  








Related examples in the same category

1.new Vector(Collection c)
2.Vector: addElement(E e)
3.Vector: add(T e)
4.Vector: clear()
5.Vector: contains(Object obj)
6.Vector: containsAll(Collection c)
7.Vector: copyInto(Object[] anArray)
8.Vector: capacity()
9.Vector: elementAt(int index)
10.Vector: elements()
11.Vector: ensureCapacity(int minCapacity)
12.Vector: equals(Object o)
13.Vector: firstElement()
14.Vector: get(int index)
15.Vector: hashCode()
16.Vector: indexOf(Object o, int index)
17.Vector: insertElementAt(E obj, int index)
18.Vector: isEmpty()
19.Vector: iterator()
20.Vector: lastElement()
21.Vector: lastIndexOf(Object o)
22.Vector: lastIndexOf(Object o, int index)
23.Vector: listIterator()
24.Vector: remove(int index)
25.Vector: remove(Object o)
26.Vector: removeAllElements()
27.Vector: removeAll(Collection c)
28.Vector: removeElementAt(int index)
29.Vector: removeElement(Object obj)
30.Vector: retainAll(Collection c)
31.Vector: set(int index, Object element)
32.Vector: setSize(int newSize)
33.Vector: size()
34.Vector: subList(int fromIndex, int toIndex)
35.Vector: toArray()
36.Vector: toArray(T[] a)
37.Save Vector to File