0

we are getting the list output values below

({1=huffs, 2=45}, {1=huffy, 2=49}, {1=huff, 2=44}, {}, {})

I want the output as below for example:

({huffs,45}, {huffy, 49}, {huff, 44}, {}, {})    
5
  • 1
    The way it's currently written it looks like a map and not a list. Can you please update the question with the corresponding type of the collection? Commented Sep 22, 2015 at 6:59
  • 1
    I cant understund your problem. Can you explain it a litle more?
    – Torsen
    Commented Sep 22, 2015 at 6:59
  • my list output is= ({1=huffs, 2=45}, {1=huffy, 2=49}, {1=huff, 2=44})
    – Nikitha
    Commented Sep 22, 2015 at 7:07
  • my list output is= ({1=huffs, 2=45}, {1=huffy, 2=49}, {1=huff, 2=44}),I need remove index of 1,2 in array
    – Nikitha
    Commented Sep 22, 2015 at 7:08
  • @Nikitha does the solution below fit yor scenario? Commented Sep 22, 2015 at 7:43

1 Answer 1

0

Your collection seems to be a list of maps. If it's just some json string, make sure to make a list of maps of it. Then try this:

public List<List<Object>> DoTheJob(List<Map<Integer,Object>> myMapList){

    List<List<Object>> resultList = new List<List<Object>>(); // your result list of lists

    for(Map<Integer,Object> m : myMapList)
    {
        List<Object> myTupple = new List<Object>();
        for (Integer key : m.keySet()) 
        {
            myTupple.Add(m.get(key));
        }
        resultList.Add(myTupple);
    }

    return resultList;
}

This should do the trick. myMapList is your input collection here ({1=huffs, 2=45}, {1=huffy, 2=49}, {1=huff, 2=44}, {}, {}). I think you should remove empty elements first. Make sure to make your collection to be in form of List<Map<Integer,Object>>.

The result is a list of lists, where each internal list is in the form of {"huff", 45}.

2
  • global static pagereference newlineSave(list<string>valuefromJSNewdata){ system.debug('Table2-valuefromJS---->'+valuefromJSNewdata); } DEBUG|Table2-valuefromJS---->({1=mu, 2=4}, {1=mu, 2=4}, {1=mu, 2=4}, {1=mu, 2=4}, {})
    – Nikitha
    Commented Sep 22, 2015 at 9:07
  • OK, it seems to be JSON collection. So, make a list-of-maps of this collection, and then use the method I wrote above. Please mark my answer as correct if it fits your requirements. Commented Sep 22, 2015 at 9:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .