Vector: indexOf(Object o) : Vector : java.util : Java by API examples (example source code) Organized by topic

Java by API
C++
PHP


Java by API  »  java.util   » [  Vector  ]   
 



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.  Vector: addElement(E e)
2.  Vector: elementAt(int index)
3.  Vector: contains(Object obj)
4.  Vector: capacity()
5.  Vector: elements()
6.  Vector: firstElement()
7.  Vector: insertElementAt(E obj, int index)
8.  Vector: lastElement()
9.  Vector: size()
10.  Save Vector to File
























Home| Contact Us
Copyright 2003 - 07 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.