0

I have a list in Java:

List<Map.Entry<String, String>> list = new ArrayList<Map.Entry<String, String>>(map.entrySet());

My question is how to convert the above java list to Javascript array like this:

var prevYear = [["2011-08-01",398], ["2011-08-02",255.25], ["2011-08-03",263.9], ["2011-08-04",154.24]];

Thanks!

typeof programmer
  • 1,509
  • 4
  • 22
  • 34
  • 4
    Have you tried anything ? Or you are just expecting to give you the code ? – StackFlowed Sep 07 '16 at 15:11
  • 1
    There are several libraries out there that convert Java objects to [JSON](http://json.org/). Take a look at the options, read up a bit about each one, and pick one you like. :) – yshavit Sep 07 '16 at 15:12
  • You can use the solution from [this](http://stackoverflow.com/a/10426838/2815219) answer. Once you have got the the return value from this function, you can use a simple `JSON.parse` in your javascript and pass the string that you received. – Raman Sahasi Sep 07 '16 at 15:13
  • You start by converting the `Map.Entry` into a `String[2]`, then ask a JSON library to format the `List` as JSON. – Andreas Sep 07 '16 at 16:21

0 Answers0