aspose file tools*
The moose likes Beginning Java and the fly likes Collections Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Collections Question" Watch "Collections Question" New topic
Author

Collections Question

Keerthi Chandhu
Greenhorn

Joined: Feb 03, 2009
Posts: 16
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
Sheriff

Joined: Sep 28, 2004
Posts: 18962
    
  40


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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18962
    
  40


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

Joined: Feb 03, 2009
Posts: 16
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

Joined: Jul 08, 2003
Posts: 24187
    
  34

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?


[Jess in Action][AskingGoodQuestions]
Keerthi Chandhu
Greenhorn

Joined: Feb 03, 2009
Posts: 16
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Collections Question