提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
搜索向量的元素
/*来 自 nowjava.com - 时代Java*/ import java.util.Vector; public class Main { public static void main(String[] args) { Vector v = new Vector(); v.add("1"); v.add("2"); v.add("3"); v.add("4"); v.add("5"); v.add("1"); v.add("2"); boolean blnFound = v.contains("3"); System.out.println("Does Vector contain 3 ? " + blnFound); int index = v.indexOf("5"); /* 来 自* 时代Java公众号 - N o w J a v a . c o m */ if(index == -1) System.out.println("Vector does not contain 5"); else System.out.println("Vector contains 5 at index :" + index); int lastIndex = v.lastIndexOf("2"); if(lastIndex == -1)