Search code examples
javavectorjava-me

How to join data of two vectors efficiently in java me?


I have two Vectors in my program and I want to join their data

Vector a=new Vector();
Vector b=new Vector();

Solution

  • Vector a = new Vector();
    Vector b = new Vector();
    
    // populate vectors a and b
    // ...
    
    Vector c = new Vector();
    
    for(Enumeration e = a.elements(); e.hasMoreElements();) {
        c.addElement(e.nextElement());
    }
    for(Enumeration e = b.elements(); e.hasMoreElements();) {
        c.addElement(e.nextElement());
    }
    
    // c now contains all elements from a followed by all elements from b