How to define and assign values to a string array in Java?

In Java, you can define a string array and assign values like this:

// 定义一个字符串数组
String[] strArray;

// 给字符串数组赋值
strArray = new String[]{"apple", "banana", "orange"};

// 或者一步到位定义并赋值
String[] strArray = new String[]{"apple", "banana", "orange"};

In the above code, a string array strArray is first defined, followed by assigning values to the array using the syntax new String[]{“apple”, “banana”, “orange”}. It is also possible to define and assign values in one step.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds