Vector类的增删找
package bag;
import java.util.Vector;
public class aaa{
public static void main(String [] args){
Vector myVector=new Vector();//
myVector.addElement(Integer.valueOf(1));//add
char ch = 'A';
myVector.insertElementAt(Character.valueOf(ch), 0);//insert
myVector.setElementAt(Integer.valueOf(2),1);//set A at place,(replace)
myVector.removeElement(Integer.valueOf(2));//remove Integer
myVector.removeElementAt(0);//remove at:i
myVector.addElement(Integer.valueOf(3));//add
myVector.removeAllElements();//格式化
myVector.addElement(Integer.valueOf(4));//add
myVector.addElement(Integer.valueOf(5));//add
myVector.addElement(Integer.valueOf(6));//add
/*for (int i:myVector-+) {
System.out.println("集合元素为"+i);
}*/
if(myVector.contains(Integer.valueOf(4))) {
int Int=(int)myVector.elementAt(0);//找第n个数
System.out.println(Int);
System.out.println(myVector.indexOf(Integer.valueOf(4),0));//向后找数
System.out.println(myVector.lastIndexOf(Integer.valueOf(5),2));//向前找数
}else {
System.out.print("false");
}
}
}
import java.util.Vector;
public class aaa{
public static void main(String [] args){
Vector myVector=new Vector();//
myVector.addElement(Integer.valueOf(1));//add
char ch = 'A';
myVector.insertElementAt(Character.valueOf(ch), 0);//insert
myVector.setElementAt(Integer.valueOf(2),1);//set A at place,(replace)
myVector.removeElement(Integer.valueOf(2));//remove Integer
myVector.removeElementAt(0);//remove at:i
myVector.addElement(Integer.valueOf(3));//add
myVector.removeAllElements();//格式化
myVector.addElement(Integer.valueOf(4));//add
myVector.addElement(Integer.valueOf(5));//add
myVector.addElement(Integer.valueOf(6));//add
/*for (int i:myVector-+) {
System.out.println("集合元素为"+i);
}*/
if(myVector.contains(Integer.valueOf(4))) {
int Int=(int)myVector.elementAt(0);//找第n个数
System.out.println(Int);
System.out.println(myVector.indexOf(Integer.valueOf(4),0));//向后找数
System.out.println(myVector.lastIndexOf(Integer.valueOf(5),2));//向前找数
}else {
System.out.print("false");
}
}
}
全部评论
相关推荐
点赞 评论 收藏
分享
点赞 评论 收藏
分享