List of usage examples for java.util Vector contains
public boolean contains(Object o)
From source file:Main.java
public static void main(String[] arguments) { String[] codes = { "alpha", "lambda", "gamma", "delta", "zeta" }; Vector list = new Vector(); for (int i = 0; i < codes.length; i++) { if (!list.contains(codes[i])) { list.add(codes[i]);/*from w w w. j a v a2 s . co m*/ } } for (Iterator ite = list.iterator(); ite.hasNext();) { String output = (String) ite.next(); System.out.println(output); } }
From source file:FindVector.java
public static void main(String args[]) { String data[] = { "Java", "Source", "and", "Support", "." }; Vector v = new Vector(); for (int i = 0, n = data.length; i < n; i++) { v.add(data[i]);// w w w . jav a2 s. c o m } System.out.println(v); System.out.println("Contains Java?: " + v.contains("Java")); System.out.println("Contains Java2s?: " + v.contains("Java2s")); System.out.println("Where's and?: " + v.indexOf("and")); System.out.println("Where's Source?: " + v.indexOf("Source")); System.out.println("Where's Java from end?: " + v.lastIndexOf("Java")); }
From source file:Main.java
public static void main(String[] args) { Vector<String> v = new Vector<String>(); v.add("1");//from w w w . j a v a 2s .c om v.add("2"); v.add("3"); v.add("4"); v.add("5"); v.add("1"); v.add("2"); System.out.println(v.contains("3")); System.out.println(v.indexOf("5")); System.out.println(v.lastIndexOf("2")); }
From source file:Main.java
public static void main(String[] args) { Vector<Integer> vec = new Vector<Integer>(4); vec.add(4);/*from w ww . j ava 2s .co m*/ vec.add(3); vec.add(2); vec.add(1); // let us check the existence of number 4 in the vector System.out.println(vec.contains(4)); }
From source file:FindVector2.java
public static void main(String args[]) { Vector v = new Vector(); for (int i = 0, n = members.length; i < n; i++) { v.add(members[i]);/* ww w . j a v a2 s . co m*/ } System.out.println(v); System.out.println("Contains Society?: " + v.contains("Society")); System.out.println("Contains Waldo?: " + v.contains("Waldo")); System.out.println("Where's Waldo?: " + v.indexOf("Waldo")); System.out.println("Where's Thoreau?: " + v.indexOf("Thoreau")); System.out.println("Where's Thoreau from end?: " + v.lastIndexOf("Thoreau")); int index = 0; int length = v.size(); while ((index < length) && (index >= 0)) { index = v.indexOf("Thoreau", index); if (index != -1) { System.out.println(v.get(index)); index++; } } }
From source file:MainClass.java
public static void main(String args[]) { Vector v = new Vector(); for (int i = 0, n = members.length; i < n; i++) { v.add(members[i]);/*from w w w . ja v a 2s .c om*/ } 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++; } } }
From source file:MainClass.java
public static void main(String args[]) { // initial size is 3, increment is 2 Vector<Integer> v = new Vector<Integer>(3, 2); System.out.println("Initial size: " + v.size()); System.out.println("Initial capacity: " + v.capacity()); v.addElement(1);/*w w w. j a va2s. c om*/ v.addElement(2); System.out.println("First element: " + v.firstElement()); System.out.println("Last element: " + v.lastElement()); if (v.contains(3)) System.out.println("Vector contains 3."); }
From source file:Main.java
public static <T> List<T> uniqueList(List<T> list) { Vector<T> v = new Vector<T>(); for (T obj : list) { if (!v.contains(obj)) { v.add((T) obj);// w w w .j av a 2 s. c o m } } return v; }
From source file:Main.java
/** Adds an object to a list if not already contained. */ public static void tryAdd(Vector vector, Object object) { if (object == null) { return;/* ww w . j a v a2 s. c o m*/ } if (!vector.contains(object)) { vector.add(object); } }
From source file:Main.java
/** Adds an object to the start of a list if not already contained. */ public static void tryInsert(Vector vector, Object object) { if (object == null) { return;// w ww . j ava 2 s .c om } if (!vector.contains(object)) { vector.insertElementAt(object, 0); } }