java - How to join the index value of two arraylists and make them a single list/set etc -


let's have 2 arraylist: firstname {a,b,c,d} , secondname {e,f,g,h}

now want list or hashmap etc. in form fullname{ae,bf,cg,dh}.

could please me in understanding collections concept in java?

below code

   import java.util.*;  public class collections1 {  public static void main(string[] args) {     // todo auto-generated method stub     arraylist<string> fname=new arraylist<>();     fname.add("a");     fname.add("b ");     fname.add("c ");     fname.add("d ");     arraylist<string> sname=new arraylist<>();     sname.add("e");     sname.add("f");     sname.add("g");     sname.add("h");      hashmap<arraylist,arraylist> fullname=new hashmap<>();     fullname.put(fname, sname);      system.out.println(fullname.keyset()+"-------------"   +fullname.values());  }    } 

try below code.

import java.util.*; public class collections1 {  public static void main(string[] args) {     // todo auto-generated method stub     arraylist<string> fname=new arraylist<>();     fname.add("a");     fname.add("b ");     fname.add("c ");     fname.add("d ");     arraylist<string> sname=new arraylist<>();     sname.add("e");     sname.add("f");     sname.add("g");     sname.add("h");      arraylist<string> fullname=new arraylist<>();      if(fname.size()==sname.size()){         for(int i=0;i<fname.size();i++){             fullname.add(fname.get(i).trim()+sname.get(i).trim());         }     }      for(int j=0;j<fullname.size();j++){         system.out.println(fullname.get(j));     }     }    } 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -