Home > Back-end >  Java recursive problems?
Java recursive problems?

Time:02-20

 
Public static & lt; T> List ExtractedList (Object o) {

//create return objects
List Result=new ArrayList (a);

//determine whether object array
If (o.g etClass (.) isArray ()) {
//is an array, the traversal
for (int i=0; I & lt; Array. GetLength (o); I++) {

//recursive, not array will return to join the list, is continues to recursive
Result. The add ((T) extractedList (Array) get (o, I)));
}

} else {
//add objects to the list
Result. The add (o) (T);
}
//return an array list
return result;//new ArrayList (result);
}

Test data
 String [] [] menuListtest=new String [] [] {{" name1 ", "text1", "cmd1", "key1"}, 
{" name2 ", "text2", "cmd2", "key2"}};

Results the
 [[[name1], [text1], [cmd1], [key1]], [[name2], [text2], [cmd2], [key2]]] 

Should the results:
 [[name1, text1, cmd1, key1], [name2, text2, cmd2, key2]] 

Don't know how to solve.
Mainly is to want to realize: I don't know the dimensions of the array of recursive transformation??????
  • Related