Skip to content

Instantly share code, notes, and snippets.

@cocoatomo
Created April 19, 2011 02:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cocoatomo/926727 to your computer and use it in GitHub Desktop.
Save cocoatomo/926727 to your computer and use it in GitHub Desktop.
配列の初期化
public class ArrayInit {
public static void main(String[] args) {
Integer[] integerArray = new Integer[] {1, 2, 3};
// String[] stringArray = new String[] {"hoge", "fuga", "piyo"};
String[] stringArray = {"hoge", "fuga", "piyo"}; // こっちで良かった.
int[] intArray = {1, 2, 3};
// Integer[] integerArray = {1, 2, 3}; # compile error
myPrintArray(new Integer[] {1, 1, 2, 3, 5});
// myPrintArray({"hoge", "fuga", "piyo"}); # compile error
myPrintArray(new String[] {"hoge", "fuga", "piyo"});
}
private static void myPrintArray(Object[] array) {
for (Object o: array) {
System.out.println(o);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment