Usage of Hashset – Selenium and Java Challenge 9

I have added Selenium and Java program below. It is based on List and and HashMap in Java. You can calculate the output and provide the comments below. Click on the button “Click for solution” to view the solution.

import org.testng.annotations.Test;

import java.util.*;

public class SampleProgram8 {

@Test
public void testMySkills() {
    System.out.println("Function returns Object with size "+findSize());
}

public int findSize() {
    List<Integer> list = new ArrayList<>();
    list.add(1);
    list.add(2);
    list.add(3);
    list.add(2);
    list.add(5);
    list.add(5);
    int size = list.size();
    HashSet<Integer> set = new HashSet();
    for(int i=0;i<size;i++) {
        set.add(list.get(i));
    }
    return set.size();
}

}

5 1 vote
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
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
0
Would love your thoughts, please comment.x
()
x