Difference between Arrays and 3 dots (Varargs) in java

后端 未结 3 783
栀梦
栀梦 2020-12-07 13:27

I cannot figure out that what are the differences between ... in java and arrays also array list, especially array list.

Both we can use as unlimited bu

3条回答
  •  庸人自扰
    2020-12-07 14:05

    The three dots can only be used in a method argument, and are called 'varargs'. It means you can pass in an array of parameters without explicitly creating the array.

    private void method(String[] args) {} is called like method(new String[]{"first", "second"});

    private void method(String... args) {} is called like method("first", "second");

提交回复
热议问题