Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass values to a function with LinkedList<String> inline? [duplicate]

I have a simple function like:

private void function(LinkedList<String> a, LinkedList<String> b)

We already know that if those arguments were only string, passing values inline would be easy, like:

function("aaa", "bbb")

But is there a way to pass inline a LinkedList?

I tried with:

function(["A", "B", "C"], ["A", "B"])

but it does not work.

like image 685
user840718 Avatar asked Nov 22 '16 17:11

user840718


1 Answers

Change the type from LinkedList to the List interface, and then you can use Arrays.asList(T...) like

function(Arrays.asList("A", "B", "C"), Arrays.asList("A", "B"))
like image 113
Elliott Frisch Avatar answered Oct 09 '22 07:10

Elliott Frisch