Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding value to List<String> = new ArrayList<String>(); [duplicate]

Tags:

java

android

list

Sorry i really dont know how to do this, last resort but to ask. I wanted to add values to the string list. But my code is not working

private List<String> sample = new ArrayList<String>(){"item1","item2","item3"};
like image 339
lonelearner Avatar asked Oct 29 '25 21:10

lonelearner


1 Answers

Here it is:

List<String> sample = new ArrayList<String>(Arrays.asList("item1", "item2", "item3"));
like image 197
wypieprz Avatar answered Nov 01 '25 12:11

wypieprz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!