My issue
what is this code used for:- for (int element : set) and how can we write direct element in sopln to print the element
My code
// Update the _ to solve
import java.util.*;
class Codechef {
public static void main(String[] args) {
Scanner read = new Scanner(System.in);
int t = read.nextInt();
for (int i = 0; i < t; i++) {
int n = read.nextInt();
ArrayList<Integer> a = new ArrayList<Integer>();
for (int j = 0; j < n; j++) {
a.add(read.nextInt());
}
HashSet<Integer> set = new HashSet<Integer>(a);
for (int element : set) {
System.out.print(element + " ");
}
System.out.println();
}
}
}
Learning course: Java for problem solving - 2
Problem Link: CodeChef: Practical coding for everyone