以下の内容はhttps://unageanu.hatenablog.com/entry/20090612/1244803133より取得しました。


配列の中身をさくっと文字列にする

配列だと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は前に使ったなー。




以上の内容はhttps://unageanu.hatenablog.com/entry/20090612/1244803133より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14