• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Collections Question

 
Keerthi Chandhu
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to check a condtion and add some values to array list. but I am unable to pass the comparision condition.

Map<String,ArrayList<String>> mapvar = new LinkedHashMap<String,ArrayList<String>>();

if(mapvar.containsKey((String)(arrList.get(i)))){
System.out.println("arrList after comparision:"+arrList.get(i));
ArrayList<String> list = (ArrayList)mapvar.get(getvalue1());
list.add(getvalue2());

}
can anyone help me to find the issue.

Thank you
 
Henry Wong
author
Marshal
Pie
Posts: 21187
80
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The Java Collection classes are part of the core API -- and is not an "Other Java API"... I am moving this topic to Java in General, Beginners.

Henry
 
Henry Wong
author
Marshal
Pie
Posts: 21187
80
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

There isn't enough information here. We don't know what this "arrList" is, and what you placed into it. We don''t know what you have in "mapvar" either... so I am not sure how we can explain whether the "if" condition should succeed or not.

Henry
 
Keerthi Chandhu
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sorry for not providing proper information.
Please find the following information.
Map<String,ArrayList<String>> mapvar = new LinkedHashMap<String,ArrayList<String>>();

mapVar is of type String and ArrayList it consists of mapVar(key1,value1) where key1=k1,k2,k3; value1=name1,name2,name3 and
ArrayList<String> arrList = new ArrayList<String>();
arrList.add(values); of type String where values=k1,k2,k3;
I am trying to compare and add all the names comes under that key in a array list.but it is not entering into the condition.
if(mapvar.containsKey((String)(arrList.get(i)))){
System.out.println("arrList after comparision:"+arrList.get(i));

}


Thank you
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, so that probably means that arrList doesn't contain what you think it does. Have you tried just adding a

System.out.println(arrList);

above the loop, so you can see for sure?
 
Keerthi Chandhu
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you are right.when I tried to print above the loop I am able to get all the array list values but I am unable to get the values after that loop because it is not passing through that condition I guess.

Thank you
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic