Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

Hi Friends, can u give code to convert ArrayList to
HashMap and HashMap to ArrayList.

Answer Posted / prashant

public class superClass {

public static void main(String[] args) {
ArrayList<String> strArrayList = new
ArrayList<String>();
strArrayList.add("Prashant");
strArrayList.add("Amol");

HashMap<Integer, String> hashMap = new
HashMap<Integer, String>();
for(int i = 0;i<strArrayList.size();i++){
hashMap.put(i, strArrayList.get(i));
}
System.out.println(hashMap);
}

}

Is This Answer Correct ?    20 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Write a program to reverse array in place?

1064


What is final variable?

938


What is use of map in java?

1009


What is string [] java?

947


What is method reference in java?

1136


What is object of class in java?

1123


What are the legal parameters?

1006


What do you mean by ordered and sorted in collections in java?

990


How can we create a synchronized collection from given collection?

1079


Write a program to print count of empty strings in java 8?

999


What is the difference between a break statement and a continue statement?

1030


What is the basic concepts of OOPS?

1190


Explain the scope of a variable.

1093


What is int argc char * argv?

1149


Difference between ‘is-a’ and ‘has-a’ relationship in java?

1003