Vector is a dynamic array implementation in Java. Hence, elements are accessible by array indexes.
A few important facts about PriorityQueue are as follows:
- It is synchronised.
Hierarchy of Vector class
It extends AbstractList and implements List, RandomAccess, Cloneable, and Serializable interfaces.
Source code of Item.java
package com.t4b.test;
public class Item {
String name;
int id;
double price;
public Item(String name, int id, double price) {
super();
this.name = name;
this.id = id;
this.price = price;
}
@Override
public String toString() {
return "Item [name=" + name + ", id=" + id + ", price=" + price + "]";
}
}
Source code of TestMain.java
package com.t4b.test;
import java.util.Vector;
public class TestMain {
public static void main(String[] args) {
Vector<Item> items = new Vector<Item>();
items.add(new Item("Apple", 1, 150.0));
items.add(new Item("Grape", 2, 250.0));
items.add(2, new Item("Mango", 3, 10));
items.addElement(new Item("Pine Apple", 4, 100));
items.insertElementAt(new Item("Goava", 5, 50), 2);
for (Item i : items)
System.out.println(i);
System.out.println(items.size());
}
}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.