Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Loptienoch;
- import java.util.*;
- public class VectorExample {
- public static void main(String args[]) {
- Vector ds = new Vector();
- //Thêm các phần tử vào ds
- ds.addElement("Nguyen Van A");
- ds.addElement("Tran Thi B");
- ds.addElement("Le Thi C");
- ds.addElement("Ho D");
- String ht= "Tran Thi B";
- if (ds.contains(ht))
- System.out.println("Có SV " + ht + " tại vị trí " + ds.indexOf(ht));
- else
- System.out.println("Không có SV " + ht);
- Enumeration e = ds.elements();
- while (e.hasMoreElements())
- System.out.println(e.nextElement());
- //Xóa phần tử
- ds.removeElement("Nguyen Van A");
- System.out.println(ds);
- System.out.println();
- Vector ds1 = new Vector();
- //Thêm các phần tử vào ds
- Integer i1 = 1;
- Integer i2 = 2;
- Integer i3 = 3;
- ds1.addElement(i1);
- ds1.addElement(i2);
- ds1.addElement(i3);
- Integer i_1 = 1;
- if (ds1.contains(i_1)){
- System.out.println("Co 1");
- }
- else System.out.println("Khong co 1");
- System.out.println();
- Vector ds2 = new Vector();
- ABC abc1 = new ABC(1, 1, "lol");
- ABC abc2 = new ABC(1, 2, "zol");
- ABC abc3 = new ABC(2, 1, "xol");
- ABC abc_1 = new ABC(1, 1, "lol");
- ds2.addElement(abc1);
- ds2.addElement(abc2);
- ds2.addElement(abc3);
- if (ds2.contains(abc_1))
- System.out.println("Co abc_1");
- else
- System.out.println("Ko co abc_1");
- if (ds2.contains(abc1))
- System.out.println("Co abc1");
- else
- System.out.println("Ko co abc1");
- System.out.println(abc1.equals(abc_1));
- System.out.println();
- Enumeration e2 = ds2.elements();
- while (e2.hasMoreElements()){
- ABC myabc = (ABC)e2.nextElement();
- System.out.println(myabc.x);
- System.out.println(myabc.y);
- System.out.println(myabc.z);
- }
- }
- }
- class ABC{
- int x;
- float y;
- String z;
- public ABC(int x, long y, String z){
- this.x = x;
- this.y = y;
- this.z = z;
- }
- public boolean equals(Object object){
- ABC myabc = (ABC)object;
- if ((this.x == myabc.x) && (this.y == myabc.y) && (this.z == myabc.z))
- return true;
- else
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment