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

Add values to a HashSet by checking the input of the method.

this solution is wrong:

public static Set match(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 match(String a) i 89e 90 91 92 93 94 95 96 97 98 unit HashSet0; new Set = Pattern p = Pattern. compile(" [A-Za-z]+"); Matcher m = p.matcher(a); entry enn.entrySet()) { : for (Map. Entry> for (String value: entry.getValueO) I 100 101 102 103 104 105 106 107 108 109 110 if (entry.getKeyC) == m.groupC)) { unit.add(value); return unit

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!