配列の中身をさくっと文字列にする
配列だとtoString()とかできないので、(これも原罪というやつか)
String[] strs = new String[]{ "a", "b", "c" }; System.out.println( strs != null ? Arrays.asList( strs ) : "null" );
とかいう感じで書いていたのだけど、Arrays.deepToString()とかあるじゃないか。
import static java.util.Arrays.deepToString; ... String[] strs = new String[]{ "a", "b", "c" }; System.out.println( deepToString( strs ) ); strs = null; System.out.println( deepToString( strs ) ); // ネストされた配列もOK String[][] strs2 = new String[][] { new String[]{ "a", "b", "c" }, new String[]{ "x" }, null }; System.out.println( deepToString( strs2 ) );
実行結果です。
[a, b, c] null [[a, b, c], [x], null]
そういえばArrays#deepEqualsは前に使ったなー。