Question: C# lets me make arrays on the fly when I need to pass them into functions. Let's say I have a method called `findMiddleItem(String[] items)`. In C#, I can write code like:

```
findMiddleItem(new String[] { "one", "two", "three" });

```

It's awesome, because it means I don't have to write:

```
IList<String> strings = new List<String>();
strings.add("one");
strings.add("two");
strings.add("three");
findMiddleItem(strings.ToArray());

```

Which sucks, because I don't really care about `strings` -- it's just a construct to let me pass a string array into a method that requires it. A method which I can't modify.

So how do you do this in Java? I need to know this for array types (eg. String[]) but also generic types (eg. List).

Answer: 
You can do it the exact same way:

```
findMiddleItem(new String[] { "one", "two", "three" });

```

is valid in Java. Assuming that `findMiddleItem` is defined as:

```
findMiddleItem(String[] array)

```
Apart from using vargs like

```
findMiddleItem("one", "two", "three", "four", "five");

```

you can do

```
findMiddleItem("one,two,three,four,five".split(","));

```

EDIT: to turn a String into a List you can use a helper method.

```
public static List<String> list(String text) {
    return Arrays.asList(text.split(","));
}

findMiddleItem(list("one,two,three,four,five"));

```