Question: Background: Consider these two code fragments: while (sc. hasNext(--*)) ...//1 static final Pattern p = Pattern.compile(--*);//2 while (sc.hasNext(p)) ...//2 What strings does the regular expression

Background: Consider these two code fragments: while (sc. hasNext("--*")) ...//1 static final Pattern p = Pattern.compile("--*");//2 while (sc.hasNext(p)) ...//2 What strings does the regular expression --* match? Why is it likely that the second fragment will be faster? Rewrite the following to apply the same optimization as was used to transform fragment 1 above into fragment 2. for (String s: ...) System.out.println(str + " " + s)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
