Avatar of MJ
MJFlag for United States of America asked on

Hashtable lookup safety net!

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.
JSPJava EEJava

Avatar of undefined
Last Comment

8/22/2022 - Mon

As I tried to point out in your previous question
an EL expression is
><%= map.get(currLocale)[0] %>  
is called a JSP expression element.

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck