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)

```
I think it's the exact same syntax in Java. This works:

```
public class Main
{
    public static void main( String[] args )
    {
        method1( new String[] {"this", "is", "a", "test"} );
    }

    private static void method1( String[] params )
    {
        for( String string : params )
            System.out.println( string );
    }
}

```

I think this will work on non-static methods, too.