Java字符串数组可以通过以下几种方式进行初始化:
- 使用字符串字面值数组初始化:
String[] strArray = {"Hello", "World", "Java"};
- 使用new关键字进行初始化:
String[] strArray = new String[3]; strArray[0] = "Hello"; strArray[1] = "World"; strArray[2] = "Java";
- 使用Arrays.asList()方法进行初始化:
String[] strArray = Arrays.asList("Hello", "World", "Java").toArray(new String[3]);
- 使用循环遍历进行初始化:
String[] strArray = new String[3]; for (int i = 0; i < strArray.length; i++) { strArray[i] = "String" + i; }