0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

可変長引数【Java】

Last updated at Posted at 2024-01-16

可変長引数とは

Java言語における可変長引数は、メソッドに任意の数の引数を渡すことができる機能です。
メソッドの定義側では配列と同じように扱います。
また、呼び出し側で直接配列を指定することも可能です。

書き方

メソッド定義側
型と引数名の間に「…」を入れて書く。

例)static void Sample(String... name) {}

異なる型を引数に指定する場合は、以下のように最後に可変長引数を定義します。

例)static void Test(int num, byte b, String... name) {}

メソッド呼び出し側
引数を通常通りカンマ区切りで定義します。

例)Sample("111", "abc", "aiueo");
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?