troubleshooting Question

Hashtable lookup safety net!

Avatar of 894359
894359Flag for United States of America asked on
JavaJSPJava EE
2 Comments1 Solution206 ViewsLast Modified:
How would I ensure my code didn't crap out if the key I use in my hashtable didn't exist?

Map <String, String[]> map = new HashMap<String, String[]>();

map.put("en_US", new String[] { "NA", "US"});
map.put("en_MX", new String[] { "NA", "MX"});

I'm surfacing via EL in the page.

var s_account="<%= map.get(currLocale)[0] %>"

How do I protect against a value not in the hashtable busting the code? Something like a default value in a switch statement.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros