-2

I have below string output :

["Kolkata","data can be, null",null,"05/31/2020",null]

but I want to have the output like below format in Java

["Kolkata","data can be, null","","05/31/2020",""]

please help me .

I am converting object to json data . Please see the below codes

List<String> test = new ArrayList<>();
List<Object[]> data =query.list();          
for (int i = 0; i < data.size(); i++) {
    Object[] row = (Object[]) data.get(i);

    String  jsonString = gson.toJson(row);
    test.add(jsonString);
} 

I want to apply this on jsonString variable using java 7 as not using java 8

lczapski
  • 4,026
  • 3
  • 16
  • 32
Pintu
  • 13
  • 1
  • 4

1 Answers1

1

If you have list for example list of like this

List<String> list = Arrays.asList("Kolkata","data can be, null",null,"05/31/2020",null);
    list.replaceAll(t -> Objects.isNull(t) ? "''" : t);
    System.out.println(list);

Here oputput will be:

[Kolkata, data can be, null, '', 05/31/2020, '']
Reeta Wani
  • 197
  • 4
  • 13
  • Please do not assume that it is a list. Always clarify before posting answers. Although it works, please don't encourage such sloppy questions by answering them. – Harshal Parekh Apr 07 '20 at 18:43
  • i am converting object to json data . Please see the below codes List test = new ArrayList<>(); List data =query.setParameterList("accIds", accIds).list(); for (int i = 0; i < data.size(); i++) { Object[] row = (Object[]) data.get(i); String jsonString = gson.toJson(row); //jsonString = jsonString.replace(null, "\"\""); test.add(jsonString); } I want to apply this on jsonString variable – Pintu Apr 07 '20 at 19:12