int[] arrc = new int[] {1, 2, 3};
System.out.println(new ArrayList(Arrays.asList(arrc)));
prints address, but i desire to use toString as in ArrayList.
Is it possible ?
Try:
import java.util.Arrays;
// ...
int[] arrc = new int[] {1, 2, 3};
System.out.println(Arrays.toString(arrc));
Note that the asList(...)
does not take an array of primitive int
's but takes Object
s instead, that's why you see an address-like String appear.
So, doing:
int[] array = {1, 2, 3};
List list = Arrays.asList(array);
results in the same as doing:
int[] array = {1, 2, 3};
List list = new ArrayList();
list.add(array);
Both result in a List that has one element in it: an array of primitive int
s.
(only that Arrays.asList(...)
returns a List that cannot be modified...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With