fork download
  1.  
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Iterator;
  5. import java.util.List;
  6. import java.util.Scanner;
  7.  
  8. class Testing {
  9.  
  10. private static Scanner sc;
  11.  
  12. @SuppressWarnings({"unchecked", "rawtypes"})
  13. public static void main(String[] args) {
  14.  
  15. ////////////////////////////////////Variables/////////////////////////////////////
  16.  
  17. String[] string;
  18. Integer[] integer = new Integer[5];
  19. Boolean[] bool = new Boolean[5];
  20. Byte[] by = new Byte[5];
  21. Double[] doub = new Double[5];
  22.  
  23. sc = new Scanner(System.in);
  24.  
  25.  
  26. /////////////////////////////////////Inputs///////////////////////////////////////
  27.  
  28. System.out.println("Enter an Array of String : ");
  29. string = sc.nextLine().split("[ ]"); //Entering dynamic String inputs for the String Types
  30.  
  31. System.out.println("Enter an Array of Integer : ");
  32. for (int i = 0; i < integer.length; i++) {
  33. integer[i] = sc.nextInt(); //Entering dynamic Integer inputs for the Integer Types
  34. }
  35.  
  36. System.out.println("Enter an Array of Boolean : ");
  37. for (int i = 0; i < bool.length; i++) {
  38. bool[i] = sc.nextBoolean(); //Entering dynamic Boolean inputs for the Boolean Types
  39. }
  40.  
  41. System.out.println("Enter an Array of Byte : ");
  42. for (int i = 0; i < by.length; i++) {
  43. by[i] = sc.nextByte(); //Entering dynamic Byte inputs for the Byte Types
  44. }
  45.  
  46. System.out.println("Enter an Array of Double : ");
  47. for (int i = 0; i < doub.length; i++) {
  48. doub[i] = sc.nextDouble(); //Entering dynamic Double inputs for the Double Types
  49. }
  50.  
  51.  
  52. ////////////////////////////////////Operations///////////////////////////////////////
  53.  
  54. ArrayList a1 = new ArrayList<String>();
  55. a1.add(string); //Inserting string array into ArrayList a1
  56.  
  57. ArrayList a2 = new ArrayList<Integer>();
  58. a2.add(integer); //Inserting integer array into ArrayList a2
  59.  
  60. ArrayList a3 = new ArrayList<Boolean>();
  61. a3.add(bool); //Inserting bool array into ArrayList a3
  62.  
  63. ArrayList a4 = new ArrayList<Byte>();
  64. a4.add(by); //Inserting by array into ArrayList a4
  65.  
  66. ArrayList a5 = new ArrayList<Double>();
  67. a5.add(doub); //Inserting doub array into ArrayList a5
  68.  
  69. ArrayList AL = new ArrayList<>();
  70. AL.add(a1); //Adding ArrayList a1 to the ArrayList AL
  71. AL.add(a2); //Adding ArrayList a2 to the ArrayList AL
  72. AL.add(a3); //Adding ArrayList a3 to the ArrayList AL
  73. AL.add(a4); //Adding ArrayList a4 to the ArrayList AL
  74. AL.add(a5); //Adding ArrayList a5 to the ArrayList AL
  75.  
  76. System.out.println("Done");
  77.  
  78. /////////////////////////////////////Displaying Output/////////////////////////////////////
  79.  
  80. for (Object object : AL) {
  81. ArrayList temp = (ArrayList) object;
  82. for (Object innerObject : temp) {
  83. if (innerObject instanceof String[]) {
  84. printArray((String[]) innerObject);
  85. } else if (innerObject instanceof Integer[]) {
  86. printArray((Integer[]) innerObject);
  87. } else if (innerObject instanceof Byte[]) {
  88. printArray((Byte[]) innerObject);
  89. } else if (innerObject instanceof Boolean[]) {
  90. printArray((Boolean[]) innerObject);
  91. } else if (innerObject instanceof Double[]) {
  92. printArray((Double[]) innerObject);
  93. }
  94. }
  95. }
  96. }
  97.  
  98. private static void printArray(Object[] obj) {
  99. for (Object ob : obj) {
  100. System.out.print(ob + ",");
  101. }
  102. System.out.println();
  103. }
  104. }
Success #stdin #stdout 0.14s 31192KB
stdin
1 2 3 4 5
1 2 3 4 5
true true true true true
1 2 3 4 5
1 2 3 4 5
stdout
Enter an Array of String : 
Enter an Array of Integer : 
Enter an Array of Boolean : 
Enter an Array of Byte : 
Enter an Array of Double : 
Done
1,2,3,4,5,
1,2,3,4,5,
true,true,true,true,true,
1,2,3,4,5,
1.0,2.0,3.0,4.0,5.0,