简体   繁体   English

如何声明字符串的动态数组?

[英]How to declare a dynamic array of String?

I want to declare an array of String whose dimension is not known. 我想声明一个String array ,其dimension未知。 How to declare and initialize it ? 如何声明和初始化它?

In Java, arrays have fixed size and the length cannot be changed once they are declared. 在Java中,数组的大小是固定的,声明后就不能更改长度。

But as suggested by others, use arraylist. 但是,正如其他人建议的那样,请使用arraylist。 Although the syntax is slightly different, array and arraylist work the same way. 尽管语法略有不同,但array和arraylist的工作方式相同。

Tutorial 讲解

Documentation 文献资料

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

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

This is a dynamic list of elements <String> 这是元素<String>的动态列表

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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