Java - new Stack <?> [N] equivalent to new Stack [N] for shared data type Stack <Item>?

Is new Stack<?>[N]equivalent new Stack[N]for a general data type Stack<Item>?

EDIT: Although I understand that it is best to avoid mixing common types and arrays, and that there are more robust solutions, my request still stands: well-known textbooks such as algorithms, 4th edition of Kevin Wayne and Robert Sedgewick (p. 158) suggest using the following constructions:

Stack<String>[] a = (Stack<String>[]) new Stack[N];
+4
source share
2 answers

Yes, they are equivalent, except for the return type (one - Stack[], the other - Stack<?>[]).

, Stack[] Stack<String>[] ( ), Stack<?>[] to Stack<String>[] .

new Stack[N] , .

+2

[ ]

1) .

2) Java Collection, ArrayList, "" , ,

ArrayList<Stack<String>> theStacks = new ArrayList<>();
+2

All Articles