« Yahoo!検索Webサービスを利用していろいろなプログラミング言語の Love Hate Ratio を求める | メイン | Double値の大小比較 (MAX_VALUE, MIN_VALUE, NaN, NEGATIVE_INFINITY, POSITIVE_INFINITY) »
2007年02月16日
java.lang.String#split の一例
ソースコード:
public class SplitTest {
public static void main(String[] args) {
String[] src = new String[]{
"a,b,c",
"a,b,",
",b,c",
",b,",
",",
"a,,b,,c",
"a,,b,,",
",,b,,c",
",,b,,",
",,",
};
for(int i=0; i<src.length; i++){
System.out.println(
src[i] +
" -> " +
src[i].split(",").length);
}
for(int i=0; i<src.length; i++){
System.out.println(
src[i] +
" -> " +
src[i].split(",", -1).length);
}
}
}
出力結果:
a,b,c -> 3
a,b, -> 2
,b,c -> 3
,b, -> 2
, -> 0
a,,b,,c -> 5
a,,b,, -> 3
,,b,,c -> 5
,,b,, -> 3
,, -> 0
a,b,c -> 3
a,b, -> 3
,b,c -> 3
,b, -> 3
, -> 2
a,,b,,c -> 5
a,,b,, -> 5
,,b,,c -> 5
,,b,, -> 5
,, -> 3
投稿者 NI-Lab. Twitter: @nilab : 2007年02月16日 21:16
« Yahoo!検索Webサービスを利用していろいろなプログラミング言語の Love Hate Ratio を求める | メイン | Double値の大小比較 (MAX_VALUE, MIN_VALUE, NaN, NEGATIVE_INFINITY, POSITIVE_INFINITY) »

コメントはこちらの Ido-Batarian BBS へどうぞ。