I am trying to write a method in java to search for an item in an array and output the indices. However, I would like it to work on arrays of different dimensions. Since I have to declare the input type as for example String[][], I can't pass a String[] as argument.
An example of what I want to achieve:
int[][] my_array1 = {{1, 2}, {3, 4}};
int[] my_array2 = {5,6};
int item1 = 2;
int item2 = 5;
search_item(my_array1, item1);
search_item(my_array2, item2);
Output:
"Index of item1:" [0][1]
"Index of item2:" [0]
I have no idea how this could be done. I tried to work with generic arrays which did not work so far.
Thank you in advance.