简体   繁体   中英

How to create multi stacks in java

I want to create many stacks using for or while but I don't have any idea.

Ex:

Stack<...> stack_1 = new Stack<>();
Stack<...> stack_2 = new Stack<>();
...
Stack<...> stack_n = new Stack<>();

Create as above is very slowly. So, I want to have an idea to create quickly many stack by for or while such as:

for (...) {
    Create stack(index) ...
}
List<Stack<Something>> stacks = new ArrayList<>(1000);
for (int i = 0; i < 1000; i++) {
   stacks.add(new Stack<Something>());
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM