Problem of the Day
Friday, January 9, 2026
Problem:
An ArrayList of String values arr contains at least one value. What does the following code print?
int x = 0;
for (int i = 1; i < arr.size(); i++)
{
if (arr.get(i).length() < arr.get(x).length())
x = i;
}
System.out.println(x);
- the string in the series that is first alphabetically
- the index of the string in the series that is first alphabetically
- the string in the series that is shortest
- the index of the string in the series that is shortest
The correct answer is d. The variable x begins with a value of 0, representing the first position in the ArrayList. The loop runs through and compares the length of the other strings in the ArrayList, and resets x to the index of any values that have a smaller length.