간단하게 한 문장으로 Variable-Length Argument Lists (즉, 파라미터를 몇개를 받아도 처리가 가능한 녀석)라고 한다.
예제코드
package honeymon.java.study;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
public class TestEllipsis {
@Test
public void testEllipsis() {
assertThat(lengthEllipsis(3, 4, 5, 6), is(4));
assertThat(countEllipsis(2, 3, 4, 5, 6), is(20));
assertThat(stringEllipsis("Korea", "Japan", "China"), is("Korea is Strong country."));
}
private String stringEllipsis(String...national) {
String stmt = null;
for (int i = 0; i < national.length; i++ ){
if("Korea".equals(national[i])) {
stmt = national[i] + " is Strong country.";
}
}
return stmt;
}
private Integer countEllipsis(int... numberArray) {
int sumresult = 0;
for (int i = 0; i < numberArray.length; i++) {
sumresult += numberArray[i];
}
return sumresult;
}
private Integer lengthEllipsis(int... number) {
return number.length;
}
}