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!

4
  • 4
    Have you tried anything ? Or you are just expecting to give you the code ? Commented Sep 7, 2016 at 15:11
  • 1
    There are several libraries out there that convert Java objects to JSON. Take a look at the options, read up a bit about each one, and pick one you like. :) Commented Sep 7, 2016 at 15:12
  • You can use the solution from this 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. Commented Sep 7, 2016 at 15:13
  • You start by converting the Map.Entry<String, String> into a String[2], then ask a JSON library to format the List<String[]> as JSON. Commented Sep 7, 2016 at 16:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.