Tuesday 15 January 2013

java - HashMap ContainsKey vs contains -



java - HashMap ContainsKey vs contains -

i have scenario below.

i have utility class foll. method.

public static map<string, string> getfeelist() { map<string, string> map = new hashmap<string, string>(); map.put("student lists", "student list"); map.put("student grade", "student grade"); homecoming map; }

i calling method in jsp , comapring value below,

feelistsmap below nil class.getfeelist() set request , retriving in jsp.

<% if(feelistsmap.containskey(vo.getsubclassdesc())){%> <td align="center">0</td> <%}else{%> <td align="center">test</td> <%}%>

from above vo.getsubclassdesc() may contain suffixes 'student list of today', 'student list of lastly month'.... above check in jsp retrive exact key value , wont work 'student list of today', 'student list of lastly month'. not want utilize substring here because map may contain more key value pair , not want utilize substring time. there easy way can compare key value subclassdesc works similar string contains() ?

there's no direct way in built-in java classes. must do

vo.getsubclassdesc().contains(key)

by looping on feelistsmap object's keys.

java string hashmap

No comments:

Post a Comment