0

How do I enter this array as an input for Java.

[[1, 5, [2, 3]], [2, 3, []], [3, 3, []]]

I've tried

int[][][] arr = {{1,5,{2,3}}, ...};
int[][] arr = ...

but both do not work. How do I do this??? Is the only way to do this is via a List???

PrashanD
  • 2,643
  • 4
  • 28
  • 58
  • did you see this example in the documentation or why do you think this would work? Have you read the documentation about array initialisation? – Tim Jun 19 '18 at 17:06
  • Actually your array is not array of just `int` but array of array as well. So you have to try `ArrayList` which can store objects of different classes. – Ashvin Sharma Jun 19 '18 at 17:07
  • 1
    What are you trying to do with this? This seems like an XY problem – GBlodgett Jun 19 '18 at 17:08
  • It's this problem off https://leetcode.com/problems/employee-importance/description/ . I'm trying to do it with ArrayList but was confused because I was wondering if that would be considered a int[][]. I'm now wondering if I'm suppose to put or – guestuser9202 Jun 19 '18 at 17:11
  • Java arrays are homogeneously typed, so you'd have to make it `Object[]`. – Andy Turner Jun 19 '18 at 17:11
  • Look at the method stub they give you. It accepts a `List` – GBlodgett Jun 19 '18 at 17:13
  • @GBlodgett How do I make an lol?? Do I have to make some Employee class? – guestuser9202 Jun 19 '18 at 17:13
  • @guestuser9202 Yes. They give you the basis of the class – GBlodgett Jun 19 '18 at 17:14
  • @GBlodgett I see public List subordinates; However, how do I put this List of Integers in it now? Do I just List arr = new ArrayList<>(); then if I try arr.add({1,5,{2,3}}); I get an error – guestuser9202 Jun 19 '18 at 17:19

0 Answers0