How to convert array into list in Java?

0 votes
How can I convert array into list in java?
Apr 24, 2018 in Java by Daisy
• 8,040 points
43 views

2 answers to this question.

0 votes

We can easily convert an array into a list in java.

Integer[] array = new Integer[] { 1, 2, 3 };

System.out.println("Array: "+array);
System.out.println("List: "+Arrays.asList(array));
answered Apr 24, 2018 by Akrati
• 3,150 points
0 votes

Another workaround if you use apache commons-lang:

int[] spam = new int[] { 1, 2, 3 };
Arrays.asList(ArrayUtils.toObject(spam));

Where ArrayUtils.toObject converts int[] to Integer[]

answered Aug 9, 2018 by samarth295
• 2,190 points

Related Questions In Java

0 votes
1 answer

How can I convert byte array into hex string in Java?

private final static char[] hexarr = "0123456789ABCDEF".toCharArray(); public ...READ MORE

answered May 24, 2018 in Java by sharth
• 3,320 points
321 views
0 votes
1 answer

How to convert a JSON String into Object in Java?

We can easily convert a JSON String ...READ MORE

answered Jun 8, 2018 in Java by parth295
• 4,600 points
254 views
0 votes
1 answer

How to convert a java string into byte array

You can probably use ByteBuffer:  byte[] byte = ...READ MORE

answered Jun 21, 2018 in Java by Perry
• 17,010 points
43 views
0 votes
1 answer

How to convert a byte into Hexadecimal in Java?

byte[] bytes = {-1, 0, 1, 2, ...READ MORE

answered Aug 21, 2018 in Java by parth295
• 4,600 points
32 views
0 votes
1 answer

Are arrays equivalent to objects in Java ?

Yes; the Java Language Specification writes: In the Java ...READ MORE

answered May 10, 2018 in Java by Rishabh
• 3,540 points
52 views
+1 vote
3 answers

What is the syntax to declare and initialize an array in java?

You can use this method: String[] strs = ...READ MORE

answered Jul 25, 2018 in Java by samarth295
• 2,190 points
256 views
0 votes
2 answers

How to concatenate two arrays in Java?

public <T> T[] concatenate(T[] a, T[] b) ...READ MORE

answered Jul 19, 2018 in Java by Sushmita
• 6,850 points
395 views
0 votes
2 answers

Array of Objects

You can also do : A[] a = ...READ MORE

answered Aug 3, 2018 in Java by sharth
• 3,320 points
32 views
+1 vote
3 answers

How to convert a List to an Array in Java?

Either: Foo[] array = list.toArray(new Foo[list.size()]); or: Foo[] array = ...READ MORE

answered Aug 7, 2018 in Java by Akrati
• 3,150 points
50 views
0 votes
2 answers

How to convert an int array to string using tostring method in java?

Use java.util.Arrays: String res = Arrays.toString(array); System.o ...READ MORE

answered 4 days ago in Java by Sirajul
• 17,910 points
188 views