I want to remove duplicate elements on the list how can you do that.

 TCS Interview Question

Q. I want to remove duplicate elements on the list how can you do that.

SOLUTION:-

package i1;

import java.util.HashSet;

import java.util.Set;


public class RemoveDuplicateUsingSet {


public static void main(String[] args) {

Set<Integer> s=new HashSet<>();

s.add(1);

s.add(2);

s.add(2);

s.add(3);

s.add(4);

s.add(5);

s.add(7);

s.add(7);


                System.out.println("Set :"+s);

}

                }

Comments

Popular posts from this blog

How to create React project using command prompt?

How to achieve abstraction?

Interview Question? How to find square of each element in this Array {2,4,5,6,8} using map ?