C. HiHowAreYou removed
System.out.print(s) will print all the elements in array list and return s.length() <=2 will return string that has string size less than or equal to 2 which is "Hi". So removeif predicate will remove Hi from the array list and "if" condition will become true.
Code-
import java.util.*;
public class Test {
public static void main(String[] args) {
String[] arr = {"Hi", "How", "Are", "You"};
List<String> arrList = new ArrayList<>(Arrays.asList(arr));
if (arrList.removeIf(s -> { System.out.print(s); return s.length() <=2;})) {
// System.out.println(arrList); //you can uncomment this print statement to see Hi getting
//removed from arraylist.
System.out.println(" removed");
}
}
}
A resposta correta é a letra C, eu testei e segue o código:
public static void main(String[] args) {
String[] arr = {"Hi", "How", "Are", "You"};
List<String> arrList = new ArrayList<>(Arrays.asList(arr));
if (arrList.removeIf(s -> { System.out.print(s); return s.length() <=2;})) {
System.out.println(" removed");
}
}
upvoted 2 times
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
DriftKing
3 months, 3 weeks agoakbiyik
1 year, 1 month agoiSnover
1 year, 3 months ago