Long.valueOf does not show zero to the left

1

I have a problem when making an append to a StringBuilder from a linkedList and display it in the form of long, the code is as follows:

   for (int i=0; i < new_list.size(); i++)
    {
        stb.append(new_list.get(i));
        Log.d("numbers stored", String.valueOf(new_list.get(i)));
    }

    Log.d("each value from", String.valueOf(new_list.toString()));
    Long requestLong = Long.parseInt(stb.toString());
    Log.d("each value from", String.valueOf(requestLong));
    return Long.valueOf(requestLong);

the value of LinkedList results in this:

[0, 8, 4, 6, 8, 9, 7, 0] 

which is the desired but at the time of making the append and using the method of Long.valueOf the result is as follows: 8468970

How can I do to show exactly the value that is stored in LinkedList ?, for your attention, thanks.

    
asked by Daniel Méndez Cruz 07.03.2017 в 06:30
source

1 answer

2

By the time you pass the String to Long you happen to have a text to a number, and a number will never have a 0 to the left. As it would happen to you with Integers , Floats or in your case Longs .

To keep that 0 on the left you must keep it in String to keep it as text and do not delete that 0 that you need.

    
answered by 07.03.2017 / 08:00
source