简体   繁体   中英

How to declare a dynamic array of String?

I want to declare an array of String whose dimension is not known. How to declare and initialize it ?

In Java, arrays have fixed size and the length cannot be changed once they are declared.

But as suggested by others, use arraylist. Although the syntax is slightly different, array and arraylist work the same way.

Tutorial

Documentation

List<String> words = new ArrayList<String>();

http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html

This is a dynamic list of elements <String>

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