How to insert vector element inside vector in java -


i have 2 set of vector , need insert second set in each of first set element , print.

my input : {red,blue,green},{csk,mi,rcb}

my output : {red,csk},{red,mi},{red,rcb},{blue,csk},{blue,mi},{blue,rcb},{green,csk},{green,mi},{green,csk}

i tried code this. can please suggest way

public static void main(string[]args){ vector v = new vector(); v.addelement("red"); v.addelement("blue"); v.addelement("green""); vector v2 = new vector(); vector v3 = new vector(); v2.addelement("csk"); v2.addelement("rcb"); v2.addelement("mi"); for(int i=0; i<v.size(); i++){     for(int j=0; j<v2.length; j++){      v3 = v(i).add(v2(j));     } } for(int i=0; i<v3.size(); i++){     system.out.println(v3); } } 

your expected output can achived in below way.

public static void main(string[]args){         vector v = new vector();         v.addelement("red");         v.addelement("blue");         v.addelement("green");         vector v2 = new vector();         vector v3 = null;         v2.addelement("csk");         v2.addelement("rcb");         v2.addelement("mi");         for(int i=0; i<v.size(); i++){             for(int j=0; j<v2.size(); j++){                 v3 = new vector();                 v3.add(v.get(i));                 v3.add(v2.get(j));                 system.out.println(v3);             }         } //      for(int i=0; i<v3.size(); i++){ //          system.out.println(v3); //      } 

from above

  1. v3 = v(i).add(v2(j)); line not compile
  2. no length in vector size
  3. to element have use get(index) method
  4. avoid using vector better go arraylist

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -