Hackerss.com

Hackerss.com is a community of amazing hackers

Hackerss is a community for developers, data scientitst, ethical hackers, hardware enthusiasts or any person that want to learn / share their knowledge of any aspect of digital technology.

Create account Log in
hackerss
hackerss

Posted on

Java How to convert java array to json array


import java.util.ArrayList;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONObject;

public class Main {
    public static void main(String[] args) {
        List<String> list = new ArrayList<String>();
        list.add("item1");
        list.add("item2");
        list.add("item3");
        JSONArray jsonArray = new JSONArray(list);
        System.out.println(jsonArray);
    }
}

/*
Output:
["item1","item2","item3"]
*/
Enter fullscreen mode Exit fullscreen mode

Latest comments (0)