KickJava   Java API By Example, From Geeks To Geeks.

Java > Java SE, EE, ME > java > util > Vector

java.util
Class Vector<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.Vector<E>
All Implemented Interfaces:
Serializable, Cloneable, Iterable<E>, Collection<E>, List<E>, RandomAccess
Direct Known Subclasses:
Stack
See Also:
Top Examples, Source Code, ArrayList, LinkedList

public boolean add(E o)
See Also:
AbstractList, List, Collection
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1245]Verctor and Arraylist
By Anonymous on 2005/01/06 08:25:00  Rate
It is better not to use the Vector anymore. ArrayList is much efficient than Vector. Use ArrayList instead whenever you don't need synchronization. All methods in Vector are synchronized by default.   
  
  
 If you do need synchronization then you can use:  
  
  
 Collections.synchronizedList ( new ArrayList (  )  ) ; 
 


public void add(int index,
                E element)
See Also:
ArrayIndexOutOfBoundsException, AbstractList, List
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void add(int index,
                Object element)
See Also:
ArrayIndexOutOfBoundsException, AbstractList, List
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[323]Using Vector
By ramki on 2004/11/01 04:28:41  Rate
Vector v = new Vector (  ) ; 
 v.add ( "Object" ) ;


[324]_
By ramki on 2005/10/09 17:43:58  Rate
Vector v = new Vector (  ) ; 
 v.add ( 1,"Object1" ) ; 
 v.add ( 2,"Object2" ) ; 
 v.add ( 3,"Object3" ) ;


[325]_
By ramki on 2003/07/22 09:22:52  Rate
/*Assume that there are indexno = "2" and  
                         signer = VectorObject in session. 
 so get these values from the session and do further*/
 
  
  
 indexno = Integer.parseInt (  ( String ) session.getAttribute ( "indexno" )  ) ; 
 Vector formVector=  ( Vector ) session.getAttribute ( "signer" ) ; 
 if  ( formVector.size (  )  == indexno )   {  
               System.out.println ( "Formvector size equals index" )  ; 
                 formVector.add ( indexno,info ) ;             
              }  else if  ( formVector.size (  )   >  indexno )   {  
                 System.out.println ( "Formvector size is greater than index" )  ;   
                
              }       


[326]_
By ramki on 2004/12/24 06:47:42  Rate
/*Assume that there are indexno = "2" and signer = VectorObject in session. AccountForm is an valueobject which contain get and set methods. and which is extends from struts ActionForm 
 so get these values from the session and do further*/
 
 ActionForm form /*pass as a parameter normally in struts*/ 
 AccountForm actform =  ( AccountForm )  form; 
 indexno = Integer.parseInt (  ( String ) session.getAttribute ( "indexno" )  ) ; 
 Vector formVector=  ( Vector ) session.getAttribute ( "signer" ) ; 
 if  ( formVector.size (  )  == indexno )   {  
       formVector.add ( indexno,info ) ; 
  }  else if  ( formVector.size (  )   >  indexno )   {  
    System.out.println ( "Formvector size is greater than index" )  ; 
  }  
 ..      


public boolean add(Object o)
See Also:
AbstractList, List
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1716]it does not print differnt values
By shrutisarade { at } yahoo { dot } co { dot } in on 2006/03/02 21:19:33  Rate
class arrayindex 
   {    
      String name; 
      long off; 
   }  
  
  
  
 Vector v=new Vector (  ) ; 
  
  
     arrayindex a=new arrayindex (  ) ; 
           //int i=0; 
         while ( m!=nameIndex.length (  )  )  
          {  
           String name1=index.readName ( 25,nameIndex ) ; 
           offset=index.readLong ( nameIndex ) ; 
           //a [ i ] .name=name1; 
           //a [ i ] .off=offset; 
           a.name=name1; 
           a.off=offset; 
           v.add ( a ) ;//.add ( a ) ;           
           m=m+58L; 
           //i++;   
     System.out.println ( "name "+name1+":"+"offset "+offset ) ; 
          }  
     //System.out.println ( "size is "+v.size (  )  ) ; 
         raf=new RandomAccessFile ( "studentdata.txt","r" ) ; 
            
          for ( c=0;c < v.size (  ) ;c++ )  
           {  
           a= ( arrayindex ) v.elementAt ( c ) ; 
             
            if (  ( a.name.trim (  )  ) .equals ( tname.trim (  )  )  )  
               {  
                 
              long offset1=a.off; 
            //  System.out.println ( "offset is in vator "+a.off ) ; 
              raf.seek ( offset1 ) ; 
             System.out.println ( "offset is in raf "+offset1 ) ; 
             s.readstudent ( raf ) ; 
             result=s.getEmailID (  ) .trim (  ) +" "+s.getGender (  ) .trim (  ) +" "+s.getAddress (  ) .trim (  ) +" "+s.getCity (  ) .trim (  ) +" "+s.getPin (  ) .trim (  ) +" "+s.getPno (  ) .trim (  ) +" "+s.getClass1 (  ) .trim (  ) ; 
             System.out.println ( "values are "+result ) ; 
             display.setText ( result ) ; 
             display.setText ( "        " ) ; 
              }  
                              
          }  
       


public boolean addAll(int index,
                      Collection<? extends E> c)
See Also:
NullPointerException, ArrayIndexOutOfBoundsException, AbstractList, List
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public boolean addAll(Collection<? extends E> c)
See Also:
AbstractCollection.add(Object), NullPointerException, List
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void addElement(E obj)
See Also:
List, add(Object)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void addElement(Object obj)
See Also:
List, add(Object)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[719]Remove duplicate value from a Vector
By smorguli { at } systag { dot } com on 2004/04/05 06:52:03  Rate
public static Vector unique  (  Vector v  )   {  
           Vector tmpVector=new Vector (  ) ;  
     String tmpValue; 
         int i ; 
          
         if  ( v.isEmpty (  )  )  return ( v ) ;         
         for  ( int j = 0; j  <  v.size (  ) ; j++ )   {  
             tmpValue =  ( String ) v.elementAt ( j ) ; 
        if  ( tmpValue!=null )   {     
       if  (  tmpVector.isEmpty (  )   )   tmpVector.addElement ( tmpValue ) ; 
                 if  ( tmpVector.indexOf ( tmpValue ) ==-1 )  {  
                 tmpVector.addElement ( tmpValue ) ; }  }                   
              } ;  
         return  (  tmpVector  )  ; 
      } 


public int capacity()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1214]Test Vector Capacity
By Sweta on 2004/12/21 14:23:27  Rate
import java.util.*; 
  
  
 class TestCapacity {  
     public static void main ( String [  ]  args )  {  
         Vector v = new Vector ( 15 ) ; 
         Integer j = null; 
         int i; 
  
  
         System.out.println ( "starting..." ) ; 
         for ( i=0;i < 10;i++ )  {  
             j = new Integer (  ( int )  ( Math.random (  )  * 100 )  ) ; 
             v.addElement ( j ) ; 
             System.out.println ( "addElement: " + j ) ; 
          }  
         System.out.println ( "size: "+v.size (  )  ) ; 
         System.out.println ( "capacity: "+v.capacity (  )  ) ;    
      }  
  } 


protected int capacityIncrement
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void clear()
See Also:
E, AbstractList, List, Collection
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public Object clone()
See Also:
Cloneable
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public boolean contains(Object elem)
See Also:
E, AbstractCollection, List, Collection
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[765]Check vector elements
By Anonymous on 2004/05/06 02:35:19  Rate
public static void main ( String [  ]  args )  {  
      
     Vector intVector=new Vector (  ) ; 
      
     for ( int i=0;i < 5;i++ )  {  
       intVector.addElement ( new Integer ( i ) .toString (  )  ) ; 
      }  
      
     if ( intVector.contains ( "3" )  )  {  
       System.out.println ( "Found it!!" ) ; 
      }  
      
      
    } 


public boolean containsAll(Collection<?> c)
See Also:
AbstractCollection.contains(Object), NullPointerException, E, List
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void copyInto(Object[] anArray)
See Also:
NullPointerException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[645]Copy vector into array
By Anonymous on 2004/02/04 12:18:28  Rate
Vector vect = new Vector (  ) ; 
 ... 
 String  [  ]  list = new String [ vect.size (  )  ] ; 
 vect.copyInto ( list ) ;


[1213]_
By Sweta on 2004/12/21 14:21:42  Rate
import java.util.*; 
  
  
 class TestVector {  
     public static void main ( String [  ]  args )  {  
         Vector v = new Vector ( 15 ) ; 
         Integer j = null; 
  
  
         int i; 
         System.out.println ( "starting..." ) ; 
         for ( i=0;i < 10;i++ )  {  
             j = new Integer (  ( int )  ( Math.random (  )  * 100 )  ) ; 
             v.addElement ( j ) ; 
             System.out.println ( "addElement: " + j ) ; 
          }  
  
  
         System.out.println ( "Converting to array" ) ; 
         Integer  [  ]  list = new Integer [ v.size (  )  ] ; 
  
  
   v.copyInto ( list ) ; 
  
  
         System.out.println ( "Printing array" ) ; 
         for ( i=0;i < v.size (  ) ;i++ )  {  
             System.out.println ( list [ i ]  ) ; 
          }  
      }  
  } 


public E elementAt(int index)
See Also:
List, get(int), ArrayIndexOutOfBoundsException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[808]_
By ashok on 2004/06/17 00:12:04  Rate
import java.util.Vector; 
 public class VectorTest 
  {  
   public static void main ( String [  ]  args )  
    {  
   Vector obj=new Vector (  ) ; 
   for ( int i=0;i < =100;i++ )  
    {  
      obj.add ( "STudent number" +i ) ; 
    }  
   for ( int i=0;i < =100;i++ )  
    {  
   System.out.println ( obj.elementAt ( i )  ) ; 
    }    
    }  
  
  
  }  
 


protected int elementCount
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


protected Object[] elementData
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public Enumeration<E> elements()
See Also:
Iterator
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1708]Retreive Elements of Vector
By Anonymous on 2006/02/07 07:29:05  Rate
Enumeration values = item.getValues (  ) .elements (  ) ; 
 while  ( values.hasMoreElements (  )  )   {  
   System.out.println (  ( String ) values.nextElement (  )  ) ; 
  }  
 


public void ensureCapacity(int minCapacity)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public boolean equals(Object o)
See Also:
Hashtable, Object.hashCode(), E, AbstractList, List, Collection
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[971]An undocumented difference in semantics between the Java 1.1.5 and Java 1.2 Vector class
By Anonymous on 2004/10/01 14:49:12  Rate
NOTE: an undocumented difference in semantics between the Java 1.1.5 and Java 1.2 Vector class. In Java 1.2, equals (  )  is defined in terms of the Vector's elements. In Java 1.1.5, equals (  )  apparently always returns false unless the two references being compared actually point to the same object.

public E firstElement()
See Also:
NoSuchElementException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public E get(int index)
See Also:
ArrayIndexOutOfBoundsException, AbstractList, List
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[678]_
By bipkumar { at } yahoo { dot } com on 2004/12/22 04:28:29  Rate
Vector v; 
 v= new Vector ( 10,2 ) ; 
  
  
     String st="a"; 
     vadding ( st ) ; 
     st="aa"; 
     vadding ( st ) ; 
     st="b"; 
     vadding ( st ) ; 
     st="bb"; 
     vadding ( st ) ; 
     st="c"; 
     vadding ( st ) ;   
     st="cc"; 
     vadding ( st ) ;   
     st="a"; 
     vadding ( st ) ; 
     st="aa"; 
     vadding ( st ) ; 
      
 System.out.println ( "comment"+v.get ( 1 )  ) ;


public int hashCode()
See Also:
Hashtable, Object.equals(java.lang.Object), E, AbstractList, List, Collection
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public int indexOf(Object elem)
See Also:
Object.equals(Object), E, AbstractList, List
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[271]Why do I get for all three index number the output 0????
By email { dot } stefan { at } web { dot } de on 2004/07/29 11:56:36  Rate
Vector OK_Seq = new Vector (  ) ; 
 ... 
 OK_Seq.addElement ( ll_S01 ) ; //Object is a LinkedList 
 OK_Seq.addElement ( ll_S02 ) ; 
 OK_Seq.addElement ( ll_S03 ) ; 
 ... 
 System.out.println ( "index of ll_S01= " + OK_Seq.indexOf ( ll_S01 )  ) ; 
 System.out.println ( "index of ll_S02= " + OK_Seq.indexOf ( ll_S02 )  ) ; 
 System.out.println ( "index of ll_S03= " + OK_Seq.indexOf ( ll_S03 )  ) ; 
 // Why do I get for all three index number the output 0?????


public int indexOf(Object elem,
                   int index)
See Also:
Object.equals(Object), IndexOutOfBoundsException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[583]_
By gautham { dot } reddy { at } bellsouth { dot } com on 2003/12/22 15:24:38  Rate
String clauseDetail="ab,cd,ef,gh,ij"; 
 int m = clauseDetail.indexOf ( ",",3 ) ;


[827]Enumerating a vector
By ambarcmendez { at } yahoo { dot } es on 2004/07/04 19:45:29  Rate
import java.util.*; 
  
  
 class AgencyData {  
   private String id; 
   private String ip; 
   private String objId; 
  
  
   public void setId  ( String id )  
      {  
     this.id=id; 
      }  
  
  
     public void setIp  ( String ip )  
      {  
     this.ip=ip; 
      }  
  
  
     public void setObjId  ( String oid )  
      {  
     this.objId=oid; 
      }  
  
  
     public String getId  (   )  
      {  
     return id; 
      }  
  
  
     public String getIp  (   )  
      {  
     return ip; 
      }  
  
  
     public String getObjId  (   )  
      {  
     return objId; 
      }  
  }  
  
  
 class vector {  
  static public void main ( String arg [  ]  )  {  
   Vector v = new Vector (  ) ; 
   AgencyData ad; 
   String cad = new String ( "agencia" ) ; 
   for ( int i=0;i < 10;i++ )  {  
     cad = cad + i; 
     ad = new AgencyData (  ) ; 
     ad.setId ( cad ) ; 
     ad.setIp ( cad ) ; 
     ad.setObjId ( cad ) ; 
     v.addElement ( ad ) ; 
    }  
  
  
   //AgencyData ad2 = new AgencyData (  ) ; 
   Enumeration enum = v.elements (  ) ; 
   while ( enum.hasMoreElements (  )  )  {  
     ad =  ( AgencyData )  enum.nextElement (  ) ; 
     System.out.print ( ad.getId (  ) +" "+ad.getIp (  ) +" "+ad.getObjId (  ) +"\n" ) ; 
    }  
   AgencyData find = new AgencyData (  ) ; 
   find.setId ( "agencia0123" ) ; 
   find.setIp ( "agencia0123" ) ; 
   find.setObjId ( "agencia0123" ) ; 
   int donde = v.indexOf ( find ) ; 
   System.out.println ( "esta en: "+donde ) ; 
   }  
  } 


public void insertElementAt(E obj,
                            int index)
See Also:
List, add(int, Object), size(), ArrayIndexOutOfBoundsException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void insertElementAt(Object obj,
                            int index)
See Also:
List, add(int, Object), size(), ArrayIndexOutOfBoundsException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public boolean isEmpty()
See Also:
E, AbstractCollection, List, Collection
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1227]Empty Vector
By kalaiselvi on 2004/12/24 01:59:12  Rate
import java.util.*; 
 public class vempty 
  {  
     public static void main ( String [  ]  args )  
      {  
      Vector v= new Vector ( 10 ) ; 
      if  ( v.isEmpty (  )  )  
   System.out.println ( "The vector is empty "+v.isEmpty (  )  ) ; 
      else 
         System.out.println ( "The vector has some elements "+v.isEmpty (  )  ) ; 
  
  
    }  
  }  
  
  
 OUTPUT 
  
  
 The vector is empty true. ( if the vector contains elements then it will return false )  
     


public E lastElement()
See Also:
NoSuchElementException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1080]Last element of vecto
By Prasanna Kalvit(meet_prasanna { at } indiatimes { dot } com) on 2004/11/03 03:39:02  Rate
import java.util.*; 
 class vec  {  
  public static void main ( String args [  ]  )  {  
  
  
  Vector v = new Vector (  ) ; 
    v.add ( "12" ) ; 
    v.add ( "13" ) ; 
    v.add ( "14" ) ; 
  
  
   System.out.println ( "the last element of vector v is "+v.lastElement (  )  ) ; 
   }  
   } 


public int lastIndexOf(Object elem)
See Also:
E, AbstractList, List
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1775]Illustrating Vector capacity, Vector LastIndexOf, Vector isEmpty methods
By Udhay Kumar on 2006/06/13 04:50:33  Rate
package com.uk.vector; 
  
  
 import java.util.Vector; 
  
  
 public class VectorSize  {  
  
  
   public static void main ( String [  ]  args )   {  
     Vector v = new Vector ( 10 ) ; 
     System.out.println ( "Vector Capacity: "+ v.capacity (  )  ) ; 
     v.add ( 0,"a" ) ; 
     v.add ( 1,"b" ) ; 
     System.out.println ( "LastIndexOf 'a' is: " + v.lastIndexOf ( "a" )  ) ; 
     System.out.println ( "LastIndexOf 'b' is: " + v.lastIndexOf ( "b" )  ) ; 
     //Check if Vector is Empty 
     if ( v.isEmpty (  )  )  
      {  
       System.out.println ( "Vector is Empty" ) ; 
      } else {  
       System.out.println ( "Vector is Not empty" ) ; 
      }  
      
    }  
  } 


public int lastIndexOf(Object elem,
                       int index)
See Also:
IndexOutOfBoundsException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public E remove(int index)
See Also:
ArrayIndexOutOfBoundsException, AbstractList, List
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public boolean remove(Object o)
See Also:
E, AbstractCollection, List, Collection
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public boolean removeAll(Collection<?> c)
See Also:
AbstractCollection.contains(Object), AbstractCollection.remove(Object), NullPointerException, E, List
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void removeAllElements()
See Also:
List, clear()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public boolean removeElement(Object obj)
See Also:
List, List.remove(Object)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void removeElementAt(int index)
See Also:
List, remove(int), size(), ArrayIndexOutOfBoundsException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[695]Add and remove vector elements
By Anonymous on 2004/03/09 09:25:33  Rate
          if  ( !strLineNr.equalsIgnoreCase (  strOldLineNr  )   )  
            {  
             log.debug ( "Ny pos hittad " + strLineNr ) ; 
             totalpos = new Element (  "TotalNumberOfReels"  ) ; 
             totpack = numOfReel; 
             strTotal = String.valueOf ( totpack ) ; 
             totalpos.addContent (  strTotal  ) ; 
              
           //  jDomTmpFile.insertChildElement (  tempElem, totalpos, counter  ) ; 
  
  
             strOldLineNr = strLineNr; 
             oldNumOfReel = numOfReel; 
             totVect.insertElementAt (  tempElem, counter  ) ; 
             log.debug ( "vetor" + totVect.toString (  )  ) ; 
             prevcounter = counter; 
            }  
           else 
            {  
             prevcounter = counter-1; 
             log.debug ( "prevR??knare= " +prevcounter ) ; 
             totalpos = new Element (  "TotalNumberOfReels"  ) ; 
             totpack = oldNumOfReel + numOfReel; 
             strTotal = String.valueOf ( totpack ) ; 
             totalpos.addContent (  strTotal  ) ; 
             log.debug ( "dublett funnen" + " " +totpack ) ; 
              
           //  jDomTmpFile.insertChildElement (  tempElem, totalpos, prevcounter  ) ; 
             totVect.removeElementAt (  prevcounter ) ; 
              totVect.insertElementAt (  tempElem, prevcounter  ) ; 
             log.debug ( "vetor" + totVect.toString (  )  + prevcounter + " "+ counter ) ; 
            } 


protected void removeRange(int fromIndex,
                           int toIndex)
See Also:
E, AbstractList
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1868]Text Parsing Example using Vector.
By shwarupbiswas { at } yahoo { dot } com on 2007/03/11 01:31:34  Rate
import java.util.*; 
 public class TestParsing 
  {  
   Vector _keyVector1,_keyVector10, _keyVector11,_keyVector12 ,_keyVector2,_keyVector20, _keyVector21,_keyVector22 ,_keyVector3, _keyVector30, _keyVector31,_keyVector32; 
    
    
    
   TestParsing (  )  
    {  
     _keyVector1=new Vector (  ) ; // contain "Salon Hours, Service Offered, Fix an appointment" of First Address. 
     _keyVector2=new Vector (  ) ; // contain "Salon Hours, Service Offered, Fix an appointment" of second Address. 
     _keyVector3=new Vector (  ) ; // contain "Salon Hours, Service Offered, Fix an appointment" of Third Address. 
       
     _keyVector10=new Vector (  ) ; // contain "Salon Hours" details of First Address.  
     _keyVector11=new Vector (  ) ; // contain "Service Offerde" details of First Address.  
     _keyVector12=new Vector (  ) ; // contain "Fix an appointment" details of First Address.   
  
  
     _keyVector20=new Vector (  ) ; // contain "Salon Hours" details of second Address.  
     _keyVector21=new Vector (  ) ; // contain "Service Offerde" details of second Address.  
     _keyVector22=new Vector (  ) ; // contain "Fix an appointment" details of second Address.   
  
  
     _keyVector30=new Vector (  ) ; // contain "Salon Hours" details of third Address.  
     _keyVector31=new Vector (  ) ; // contain "Service Offerde" details of third Address.  
     _keyVector32=new Vector (  ) ; // contain "Fix an appointment" details of third Address.       
      
    }  
   public void parse (  )  
    {  
     // clearing the vectors before each request. 
     _keyVector1.removeAllElements (  ) ; 
     _keyVector2.removeAllElements (  ) ; 
     _keyVector3.removeAllElements (  ) ; 
  
  
     _keyVector10.removeAllElements (  ) ; 
     _keyVector11.removeAllElements (  ) ; 
     _keyVector12.removeAllElements (  ) ; 
  
  
     _keyVector20.removeAllElements (  ) ; 
     _keyVector21.removeAllElements (  ) ; 
     _keyVector22.removeAllElements (  ) ; 
  
  
     _keyVector30.removeAllElements (  ) ; 
     _keyVector31.removeAllElements (  ) ; 
     _keyVector32.removeAllElements (  ) ; 
  
  
     Vector v1,v2,v3; // local vector declaration for storing "salon hours, service offered and fix an appointment" information with out parsing ','. 
     v1=new Vector (  ) ;   
     v2=new Vector (  ) ;   
     v3=new Vector (  ) ;  
  
  
     String _text="Id=4|1.Salon Hours| Mon:9A.M.-7P.M, Tue:9A.M.-7P.M, Wed:9A.M.-7P.M, Thu:9A.M.-7P.M, Fri:9A.M.-7P.M, Sat:9A.M.-7P.M, Sun:close|^|2.Service Provided| XYZ,ABC,PQR|^|3.Fix an Appointment|Contact with Customer Care, +91-9884134294,Shwarup/Biswas|^|#|1.Salon Hours 1|Mon:9A.M.-7P.M, Tue:9A.M.-7P.M, Wed:9A.M.-7P.M, Thu:9A.M.-7P.M, Fri:9A.M.-7P.M, Sat:9A.M.-7P.M, Sun:close|^|2.Service Provided 1|XYZ1 ,ABC 1,PQR1|^|3.Fix an Appointment 1|Contact with Customer Care, +91-9884134294,Shwarup/Biswas 1|^|#|1.Salon Hours 3|Mon:9A.M.-7P.M, Tue:9A.M.-7P.M, Wed:9A.M.-7P.M, Thu:9A.M.-7P.M, Fri:9A.M.-7P.M, Sat:9A.M.-7P.M, Sun:close|^|2.Service Provided 3|XYZ 2,ABC 2,PQR 2|^|3.Fix an Appointment 3|Contact with Customer Care, +91-9884134294,Shwarup/Biswas 2|^|#|*"; 
     String _tempText="";  
  
  
     boolean keyFlag = false; 
     int dataCounter = 1; 
  
  
     for ( int i=4;i < _text.length (  ) ;i++ )  
      {  
       char ch=_text.charAt ( i ) ; 
       if ( ch!='#' )  
        {  
         if ( ch!='^' )  
          {  
           if ( ch!='|' )        
            {  
             _tempText+=ch; 
            }  
           else  
            {  
             if ( _tempText != "" )  
              {          
         if ( dataCounter==1 )  
          {  
                 if ( !keyFlag )  
                  {  
       //System.out.println ( "dataCounter 1 =" + dataCounter ) ; 
       _keyVector1.addElement ( new String ( _tempText )  ) ; 
       _tempText=""; 
        keyFlag=true; 
            }  
            else 
            {  
       v1.addElement ( new String ( _tempText )  ) ; 
       _tempText=""; 
       keyFlag=false; 
            }  
          }  
         else if ( dataCounter==2 )  
          {  
                 if ( !keyFlag )  
                  {  
       _keyVector2.addElement ( new String ( _tempText )  ) ; 
       _tempText=""; 
        keyFlag=true; 
            }  
            else 
            {  
       //System.out.println ( "dataCounter 2 =" + dataCounter ) ; 
       v2.addElement ( new String ( _tempText )  ) ; 
       _tempText=""; 
       keyFlag=false; 
            }  
          }  
         else if ( dataCounter==3 )  
          {  
     //System.out.println ( "dataCounter 3 =" + dataCounter ) ; 
                 if ( !keyFlag )  
                  {  
       _keyVector3.addElement ( new String ( _tempText )  ) ; 
       _tempText=""; 
        keyFlag=true; 
            }  
            else 
            {  
       v3.addElement ( new String ( _tempText )  ) ; 
       _tempText=""; 
       keyFlag=false; 
            }  
          }  
              }  
            }  
          }  
   else  
     keyFlag=false; 
        }  
       else  
        {  
   dataCounter ++; 
   keyFlag=false;   
        }  
      }  
 // Parsing First address data. 
  
  
     for ( int j=0;j < v1.size (  ) ;j++ )  
      {  
        String vectorElement_0 =  ( String ) v1.elementAt ( j ) ; 
        String tempData=""; 
        vectorElement_0 +=','; 
        for ( int i=0;i < vectorElement_0.length (  ) ;i++ )  
         {  
          char ch=vectorElement_0.charAt ( i ) ;         
          if ( ch!=',' )  
           {  
             if ( ch == ':' )  
              {          
               tempData+=ch; 
         tempData+=' '; 
        }  
       else 
        {  
         tempData+=ch; 
        }  
           }  
          else 
           {  
       if ( j==0 )  
        {  
                _keyVector10.addElement ( new String ( tempData )  ) ; 
          tempData=""; 
        }  
       if ( j==1 )  
        {  
                _keyVector11.addElement ( new String ( tempData )  ) ; 
          tempData=""; 
        }  
       if ( j==2 )  
        {  
                _keyVector12.addElement ( new String ( tempData )  ) ; 
          tempData=""; 
        }  
  
  
           }  
         }      
       }  
      for ( int i=0;i < _keyVector10.size (  ) ;i++ )    
         System.out.println ( "KeyVector10 [ "+i+" ]  = "+_keyVector10.elementAt ( i )  ) ;      
  
  
      for ( int i=0;i < _keyVector11.size (  ) ;i++ )    
         System.out.println ( "KeyVector11 [ "+i+" ]  = "+_keyVector11.elementAt ( i )  ) ;      
  
  
      for ( int i=0;i < _keyVector12.size (  ) ;i++ )    
         System.out.println ( "KeyVector12 [ "+i+" ]  = "+_keyVector12.elementAt ( i )  ) ;  
  
  
 // Parsing second address data. 
  
  
     for ( int j=0;j < v2.size (  ) ;j++ )  
      {  
        String vectorElement =  ( String ) v2.elementAt ( j ) ; 
        String tempData=""; 
        vectorElement +=','; 
        for ( int i=0;i < vectorElement.length (  ) ;i++ )  
         {  
          char ch=vectorElement.charAt ( i ) ;         
          if ( ch!=',' )  
           {  
             if ( ch == ':' )  
              {          
               tempData+=ch; 
         tempData+=' '; 
        }  
       else 
        {  
         tempData+=ch; 
        }  
           }  
          else 
           {  
       if ( j==0 )  
        {  
                _keyVector20.addElement ( new String ( tempData )  ) ; 
          tempData=""; 
        }  
       if ( j==1 )  
        {  
                _keyVector21.addElement ( new String ( tempData )  ) ; 
          tempData=""; 
        }  
       if ( j==2 )  
        {  
                _keyVector22.addElement ( new String ( tempData )  ) ; 
          tempData=""; 
        }  
  
  
           }  
         }      
       }  
      for ( int i=0;i < _keyVector20.size (  ) ;i++ )    
         System.out.println ( "KeyVector20 [ "+i+" ]  = "+_keyVector20.elementAt ( i )  ) ;      
  
  
      for ( int i=0;i < _keyVector21.size (  ) ;i++ )    
         System.out.println ( "KeyVector21 [ "+i+" ]  = "+_keyVector21.elementAt ( i )  ) ;      
  
  
      for ( int i=0;i < _keyVector22.size (  ) ;i++ )    
         System.out.println ( "KeyVector22 [ "+i+" ]  = "+_keyVector22.elementAt ( i )  ) ;  
  
  
 // Parsing Third address data. 
  
  
     for ( int j=0;j < v3.size (  ) ;j++ )  
      {  
        String vectorElement =  ( String ) v3.elementAt ( j ) ; 
        String tempData=""; 
        vectorElement +=','; 
        for ( int i=0;i < vectorElement.length (  ) ;i++ )  
         {  
          char ch=vectorElement.charAt ( i ) ;         
          if ( ch!=',' )  
           {  
             if ( ch == ':' )  
              {          
               tempData+=ch; 
         tempData+=' '; 
        }  
       else 
        {  
         tempData+=ch; 
        }  
           }  
          else 
           {  
       if ( j==0 )  
        {  
                _keyVector30.addElement ( new String ( tempData )  ) ; 
          tempData=""; 
        }  
       if ( j==1 )  
        {  
                _keyVector31.addElement ( new String ( tempData )  ) ; 
          tempData=""; 
        }  
       if ( j==2 )  
        {  
                _keyVector32.addElement ( new String ( tempData )  ) ; 
          tempData=""; 
        }  
  
  
           }  
         }      
       }  
  
  
      // Displaying the informations from the vector. 
      for ( int i=0;i < _keyVector30.size (  ) ;i++ )    
         System.out.println ( "KeyVector30 [ "+i+" ]  = "+_keyVector30.elementAt ( i )  ) ;      
  
  
      for ( int i=0;i < _keyVector31.size (  ) ;i++ )    
         System.out.println ( "KeyVector21 [ "+i+" ]  = "+_keyVector31.elementAt ( i )  ) ;      
  
  
      for ( int i=0;i < _keyVector32.size (  ) ;i++ )    
         System.out.println ( "KeyVector32 [ "+i+" ]  = "+_keyVector32.elementAt ( i )  ) ;  
  
  
    }  
  
  
   public static void main ( String [  ]  args )  
    {  
     TestParsing tp=new TestParsing (  ) ; 
     tp.parse (  ) ; 
    }  
  } 


public boolean retainAll(Collection<?> c)
See Also:
AbstractCollection.contains(Object), AbstractCollection.remove(Object), NullPointerException, E, List
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public E set(int index,
             E element)
See Also:
ArrayIndexOutOfBoundsException, AbstractList, List
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public Object set(int index,
                  Object element)
See Also:
IllegalArgumentException, ArrayIndexOutOfBoundsException, AbstractList, List
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setElementAt(E obj,
                         int index)
See Also:
set(int, java.lang.Object), List, size(), ArrayIndexOutOfBoundsException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setElementAt(Object obj,
                         int index)
See Also:
set(int, java.lang.Object), List, size(), ArrayIndexOutOfBoundsException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setSize(int newSize)
See Also:
ArrayIndexOutOfBoundsException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public int size()
See Also:
E, AbstractCollection, List, Collection
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1226]Vector size
By kalaiselvi on 2004/12/29 02:15:18  Rate
import java.util.Vector; 
 public class vsize 
  {  
     public static void main ( String [  ]  args )  
      {  
       Vector obj=new Vector (  ) ; 
       //adding elements into vector  
       for ( int i=0;i < =50;i++ )  
           obj.add ( new Integer ( i )  ) ; 
      
       System.out.println ( "THE VECTOR SIZE"+obj.size (  )  ) ; 
  
  
      }  
  }  
  
  
 OUTPUT: 
 THE SIZE OF VECTOR:51 ( Since array index starts from 0 )  
  
  
 


[1234]_
By kalaiselvi on 2004/12/28 04:19:46  Rate
import java.util.Vector; 
 public class vsize 
  {  
     public static void main ( String [  ]  args )  
      {  
     Vector obj=new Vector (  ) ; 
     for ( int i=0;i < =50;i++ )  
           obj.add ( new Integer ( i )  ) ; 
      
   System.out.println ( obj.size (  )  ) ; 
  
  
      }  
  } 


public List<E> subList(int fromIndex,
                       int toIndex)
See Also:
IllegalArgumentException, IndexOutOfBoundsException, AbstractList
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public Object[] toArray()
See Also:
Arrays.asList(Object[]), E, AbstractCollection, List, Collection
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public Object[] toArray(Object[] a)
See Also:
ArrayStoreException, AbstractCollection, List
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public <T> T[] toArray(T[] a)
See Also:
NullPointerException, ArrayStoreException, E, AbstractCollection, List, Collection
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1325]Vector to array
By anand { dot } chauhan { at } nyu { dot } edu on 2005/03/17 08:02:31  Rate
String [  ]  stringArrayType = new String [ vec.size (  )  ] ; 
 String [  ]  stringArray =  ( String [  ]  )  vec.toArray ( stringArrayType ) ;


public String toString()
See Also:
E, AbstractCollection
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void trimToSize()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public Vector()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[432]Two ways to retrive elements from a vector
By Jim on 2004/04/22 04:21:44  Rate
//Create a vector 
 List myVector = new Vector (  ) ; 
  
  
 // Populate a vector 
 String object1 = "object 1"; 
 String object2 = "object2"; 
 myVector.add ( object1 ) ; 
 myVector.add ( object2 ) ; 
  
  
 // Retrieve objects 
 Iterator myIterator = myVector.iterator (  ) ; 
 while ( myIterator.hasNext (  )  )  {  
 String myString =  ( String ) myIterator.next (  ) ; 
 System.out.println ( "myString=" + myString + "\n" ) ; 
  }  
  
  
 // Another way to retrieve objects 
 String myNextString1 =  ( String ) myVector.get ( 0 ) ; 
 String myNextString2 =  ( String ) myVector.get ( 1 ) ; 
 out.println ( "myNextString1=" + myNextString1 + "\n" ) ; 
 out.println ( "myNextString2=" + myNextString2 + "\n" ) ;


public Vector(int initialCapacity)
See Also:
IllegalArgumentException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1676]Vector and ArrayList difference
By Anonymous on 2005/11/04 20:23:08  Rate
Vector is synchronized whereas arraylist is not.

public Vector(int initialCapacity,
              int capacityIncrement)
See Also:
IllegalArgumentException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public Vector(Collection<? extends E> c)
See Also:
NullPointerException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  

Popular Tags