BAEL-1250 Initializing Arrays in Java
This commit is contained in:
parent
595f6e3de0
commit
26f495afa7
|
@ -2,6 +2,8 @@ package com.baeldung.array;
|
|||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
|
||||
public class ArrayInitializer {
|
||||
|
||||
public static int[] initializeArrayInLoop() {
|
||||
|
@ -71,4 +73,9 @@ public class ArrayInitializer {
|
|||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public static char[] initializeArrayUsingArraysUtilClone() {
|
||||
char[] array = new char[] {'a', 'b', 'c'};
|
||||
return ArrayUtils.clone(array);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import static com.baeldung.array.ArrayInitializer.initializeArrayRangeUsingArray
|
|||
import static com.baeldung.array.ArrayInitializer.initializeArrayUsingArraysCopy;
|
||||
import static com.baeldung.array.ArrayInitializer.initializeArrayUsingArraysFill;
|
||||
import static com.baeldung.array.ArrayInitializer.initializeArrayUsingArraysSetAll;
|
||||
import static com.baeldung.array.ArrayInitializer.initializeArrayUsingArraysUtilClone;
|
||||
import static com.baeldung.array.ArrayInitializer.initializeLargerArrayUsingArraysCopy;
|
||||
import static com.baeldung.array.ArrayInitializer.initializeMultiDimensionalArrayInLoop;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
|
@ -65,4 +66,8 @@ public class ArrayInitializerTest {
|
|||
public void whenInitializeLargerArrayRangeUsingArraysSetAll_thenCorrect() {
|
||||
assertArrayEquals(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, initializeArrayUsingArraysSetAll());
|
||||
}
|
||||
|
||||
public void whenInitializeArrayUsingArraysUtilClone_thenCorrect() {
|
||||
assertArrayEquals(new char[] { 'a', 'b', 'c' }, initializeArrayUsingArraysUtilClone());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue