简体   繁体   中英

How to construct array of values in Java

I have to return a JSON string in this format using Spring. My Spring controller will take care of this since I specify the return value as @ResponseBody . Now I have to construct the value in Java in the following format:

["Male", "m"]

Please help me to get this done in Java.

Return String[] or List<String> . Either of these should work.

System.out.println(
       Arrays.toString(new String[] {"Male", "m"})); // prints: ["Male", "m"]

// if the data comes as a dynamic List
String list = Arrays.asList("Male", "m").toString();
System.out.println(list); // prints: ["Male", "m"]

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