1423/how-to-convert-an-array-to-arraylist
import java.util.*; public class ArrToArrList { public static void main(String[] args) { /* Array Declaration and initialization*/ String names[]={"George", "Sam", "Mac", "Alia"}; /*Array to ArrayList conversion*/ ArrList<String> names= new ArrList<String>(Arrays.asList(citynames)); /*Adding new elements to the converted List*/ names.add("Smit"); names.add("Peter"); /*Final ArrayList content display using for*/ for (String str: names) { System.out.println(str); } } }
In Java 9 you can use:
List<String> list= List.of("Hello", "World", "from", "Java"); List<Integer> list = List.of(1, 2, 3, 4, 5);
In Java 8 or later: String listString = ...READ MORE
new ArrayList<>(Arrays.asList(array)); READ MORE
I'd want to transform the following object: {"1":5,"2":7,"3":0,"4" ...READ MORE
public static final String[] VALUES = new ...READ MORE
In Java 8 or earlier: List<String> string = ...READ MORE
Use like this. List<String> stockList = new ArrayList<String>(); stockList.add("stock1"); stockList.add("stock2"); String[] ...READ MORE
How can I convert a List to an Array in Java? Check ...READ MORE
You can use this method: String[] strs = ...READ MORE
Either: Foo[] array = list.toArray(new Foo[list.size()]); or: Foo[] array = ...READ MORE
Use java.util.Arrays: String res = Arrays.toString(array); System. ...READ MORE
OR
At least 1 upper-case and 1 lower-case letter
Minimum 8 characters and Maximum 50 characters
Already have an account? Sign in.