Question: Add values to a HashSet by checking the input of the method. for example: if input AAA111, and the key of enr AAA323: ( if
Add values to a HashSet by checking the input of the method.
for example: if input AAA111, and the key of enr AAA323: ( if letters matches)
add the value of both to the Set

this solution is wrong:
public static Setmatch(String a) { Set unit = new HashSet (); Pattern p = Pattern.compile("[A-Za-z]+"); Matcher matcher = p.matcher(a); if(matcher.find()) { String aMatch = matcher.group(); for (Map.Entry > entry : enr.entrySet()) { for (String value : entry.getValue()) { matcher = p.matcher(value); if (matcher.find() && matcher.group().equals(aMatch)) { unit.add(value); } } } } return unit; }
public static Set
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
