What is the output of the following Java program? – Selenium and Java Challenge 1

I have started a 30-day Selenium with Java challenge to help beginners and intermediate software testers for learning Selenium and Java concepts. This is first challenge. Share your answers in the comments about the program’s output—I’ll provide my short answer afterward.

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.testng.annotations.Test;

public class SampleProgram1 {

@Test
public void testMySkills() {
    System.out.println(getListItem());
}

public int getListItem() {
    List<Integer> list = new ArrayList<>();
    list.add(8);
    list.add(9);
    list.add(6);

    int i = 0;
    for (int num : list) {
        list.set(i, num + 10);
        i++;
    }

    Collections.sort(list);
    return list.get(0);
}

}

0 0 votes
Article Rating
Subscribe
Notify of
guest

4 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
princy

initial list=[8, 9, 6]
Adding 10 to each element in the list
new list=[18,19,16]
After sorting
list=[16,18,19]
The output is the first element from the list=16.

princy

Thanks

Testingtalkslatest.com - A project by CreativeHub IT Solutions.
Contact Us At: support@testingtalkslatest.com
Our Partner websites - Classified Hub , CodesToolbox , Smart Fitness Guide , CodesToolbox , Testing Forum
Scroll to Top
4
0
Would love your thoughts, please comment.x
()
x