Jeet.Deir Jeet.Deir - 2 months ago 21
Java Question

Singleton Collection To Multiple Object Collection

So I was initially using a singleton list to pass data to Google Cloud API like this:

inputInput.setCsvInstance(Collections.<Object>singletonList("Ear"));


How can I change the
singletonList
to send multiple objects like this:

inputInput.setCsvInstance(Collections.<Object>singletonList("5.656346", "2.43485744", ...));


EDIT: I don't want to keep a singleton. I need to change it to multiple one, singleton doesn't allow me that. What keyword should I use instead of singleton is my question.

Thanks.

Answer

A singleton list has only 1 element by definition. If you want a list with multiple elements, you can use Arrays.asList():

inputInput.setCsvInstance(Arrays.asList("5.656346", "2.43485744", ...));
Comments