开发者

match the label and get value from Labelvaluebean

I'm gettin开发者_如何学JAVAg a list of organization type and code are stored as labelvaluebean as below: [LabelValueBean[ORG1, XX], [ORG2, AA]] - in array.

later these values are stored in a session variable. My question is, is there a way I can search thru this array to match the name and get the code ? (for ex: match with ORG1 and get XX). If user enter ORG1, I should send XX to back-end.


This sounds like you want to be using a Map instead of an array. A Map will store...mappings...between keys and values - think of it like a table with 2 columns, where the first column is your organization type and the second column is the code. You then take an organization code, look in your table at the values in the first column until you find a match, then you look over at the second column for the code, and return it. Obviously, this is handled by the Map implementation used, so all you need to do is declare what Objects should be used as the keys and values. In your case, maybe you'll have a Map<String, String>.

For example,

Map<String, String> map = new HashMap<String, String>();
map.put("ORG1", "XX");
map.put("ORG2", "AA");
map.get("ORG1") // returns "XX"
map.get("ORG2") // returns "AA"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜