-1

I have a list which looks like this:

[{name=test19}, {name=test20}]

with the format

List<Map<String, Object>>

how can I remove "name=" from each element and the "{}" and add """" so the list looks like this:

["test19", "test20"]

It requires some kind of iteration, right? I have tried the example here another thread but it doesn't work. Why it doesn't work is because it doesn't even go into the for loop (I have tried casting types etc)

Community
  • 1
  • 1
benskiiii
  • 439
  • 3
  • 11
  • 23

1 Answers1

3

I think you only need to fetch the values from the pairs and store them in a list.

List<Object> list = new ArrayList<Object>();
for (Map.Entry<String, Object> entry: map.entrySet) {
    list.add(entry.getValue());
}
String stringRepresentation = list.toString();

If you print stringRepresentation you will get the desired output

Konstantin Yovkov
  • 62,134
  • 8
  • 100
  • 147
  • Well, maybe the OP could have tried by himself (even if you're probably right). – sp00m Oct 14 '14 at 11:36
  • Sorry I didnt understand this, how does this remove those strings? Do you mean that I should convert it all to string and then remove them? Sorry for the misunderstandning – benskiiii Oct 14 '14 at 11:37
  • No, you don't remove anything. You have a map (a key-value data structure), from which you just *extract* the values and copy them into a separate list. – Konstantin Yovkov Oct 14 '14 at 11:38