• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Collections Question

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
eat bricks! HA! And here's another one! And a tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic