Hello Programmers, In this post, you will know how to solve the Java Arraylist HackerRank Solution. This problem is a part of the HackerRank Java Programming Series.Java Arraylist HackerRank SolutionsOne more thing to add, don’t directly look for the solutions, first try to solve the problems of Hackerrank by yourself. If you find any difficulty after trying several times, then you can look for solutions.Java Arraylist HackerRank SolutionProblemSometimes it’s better to use dynamic size arrays. Java’s Arraylist can provide you this feature. Try to solve this problem using Arraylist.You are given lines. In each line there are zero or more integers. You need to answer a few queries where you need to tell the number located in position of line.Take your input from System.in.Input FormatThe first line has an integer . In each of the next lines there will be an integer denoting number of integers on that line and then there will be space-separated integers. In the next line there will be an integer denoting number of queries. Each query will consist of two integers and .ConstraintsEach number will fit in signed integer.Total number of integers in lines will not cross .Output FormatIn each line, output the number located in position of line. If there is no such position, just print “ERROR!”Sample Input5 5 41 77 74 22 44 1 12 4 37 34 36 52 3 20 22 33 5 1 3 3 4 3 1 4 3 5 5 Sample Output74 52 37 ERROR! ERROR! ExplanationThe diagram below explains the queries:Java Arraylist HackerRank Solutionsimport java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); List<List<Integer>> lines = new ArrayList<List<Integer>>(); int n = in.nextInt(); for (int i = 0; i < n; i++) { List<Integer> line = new ArrayList<Integer>(); int d = in.nextInt(); for (int j = 0; j < d; j++) { line.add(in.nextInt()); } lines.add(line); } int q = in.nextInt(); for (int i = 0; i < q; i++) { int x = in.nextInt(); int y = in.nextInt(); if (y > lines.get(x - 1).size()) { System.out.println("ERROR!"); } else { System.out.println(lines.get(x - 1).get(y - 1)); } } in.close(); } }Disclaimer: The above Problem (Java Arraylist) is generated by Hackerrank but the Solution is Provided by BrokenProgrammers. This tutorial is only for Educational and Learning purposes.Next: Java 1D Array (Part 2) HackerRank Solution Post navigationJava Subarray HackerRank Solution Java 1D Array (Part 2) HackerRank Solution