I'm trying to take the following line as input in Java but not getting the desired output. I want all of those integers in an Array List.
Input:
- 2 (test cases)
- 5 (size of first test case array)
- 1 2 3 5 4(Elements in first test case array)
- 4 (size of second test case array)
- 66 45 778 51(Elements in second test case array)
Code:
import java.util.*;
import java.lang.*;
public class Main
{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        //System.out.println("Hello World");
        int tc = sc.nextInt();
        for(int i = 0; i < tc; i++){
            ArrayList<Integer> list = new ArrayList<Integer>();
            int t = sc.nextInt();
            String line = sc.next();
            String[] arr = line.split(" ");
            for(int j = 0; j < t; j++)   
                list.add(Integer.parseInt(arr[j]));
            System.out.print(list);
        }
    }
}
Output
1
5
1 2 3 4 5
[1]
 
     
     
     
    