Java Core : Storing and Showing Objects in a Vector

Vector is used  to hold  object and show its  value  in different way ( useful  shopping cart handling)

import java.util.Enumeration;
import java.util.Iterator;
import java.util.Vector;
class  items
{
    	private String name;
		private double price;

		void setName(String n)
		{
		name=n;
		}
	
		String getName()
		{
		return(name);
		}
		
		void setPrice(double p)
		{
		price=p;
		}
	
		double getPrice()
		{
		return(price);
		}
}


public class holdObject 
{

	 public   static void main(String  args[])
	 {
	 
		 	items  a= new items();
		 	items  b= new  items();
		 	a.setName("TFT");
		 	a.setPrice(345);
	 
		 	b.setName("LED");
		 	b.setPrice(300);
		 		
		 	Vector<items> itemList = new Vector<items>(); 
		 	itemList.add(a);
		 	itemList.add(b);
		 	
			System.out.println("---------way-1-----------------");
		 	for (Enumeration<items> e = itemList.elements(); e.hasMoreElements();)
		 	{
		 	items  pr=e.nextElement();
		 	String nm = (String)pr.getName() ;
		 	double p= (double)pr.getPrice() ;
		 	System.out.println(nm +"|"+ p);
		 	}
			System.out.println("----------way-2----------------");
		 	
		 	Iterator vtr = itemList.iterator();
		 	while( vtr.hasNext())
		 	{
		 		items  pr=(items) vtr.next();
	 	 		String nm = (String)pr.getName() ;
			 	double p= (double)pr.getPrice() ;
			 	System.out.println(nm +"|"+ p);
		 	}
		 	
		 	
			System.out.println("----------way-3----------------");
		 	Enumeration ve =  itemList.elements(); 
		 	while(ve.hasMoreElements())
		 	{
		 		items  pr=(items) ve.nextElement();
	 	 		String nm = (String)pr.getName() ;
			 	double p= (double)pr.getPrice() ;
			 	System.out.println(nm +"|"+ p);
		 	}
		 	
			System.out.println("------------way-4--------------");
		 	for(items p:itemList)
		 	{
		 		System.out.println(p.getName() +"|"+ p.getPrice());
		 	}
		 		 	
		 	
		 	System.out.println("----------way-5----------------");
		 	for( int x=0; x< itemList.size();x++)
		 	{
		 		items  pr=(items) itemList.elementAt(x);
	 	 		String nm = (String)pr.getName() ;
			 	double p= (double)pr.getPrice() ;
			 	System.out.println(nm +"|"+ p);
		 	}
		 	 
	 }

}

output…..

———way-1—————–
TFT|345.0
LED|300.0
———-way-2—————-
TFT|345.0
LED|300.0
———-way-3—————-
TFT|345.0
LED|300.0
————way-4————–
TFT|345.0
LED|300.0
———-way-5—————-
TFT|345.0
LED|300.0