在Java中,有以下几种方式来定义字符串数组:
String[] strArray = {"Hello", "World"};
String[] strArray = new String[3];
strArray[0] = "Hello";
strArray[1] = "World";
strArray[2] = "!";
String[] strArray = (String[]) Array.newInstance(String.class, 3);
strArray[0] = "Hello";
strArray[1] = "World";
strArray[2] = "!";
需要注意的是,以上方式都是定义一个一维字符串数组。如果需要定义多维字符串数组,可以通过嵌套以上方式来实现。例如:
String[][] strArray = {{"Hello", "World"}, {"Java", "Programming"}};