「Java」java.lang.String.split()で文字列を分割する

サンプルコード

package com.arkgame.study;

public class SplitDemoStr {

	public static void main(String[] args) {
		String cft = new String("Welcome-to-arkgame.com");

		System.out.println("");
		System.out.println("-1_return value:");
		for (String rr : cft.split("-", -1)) {
			System.out.println(rr);
		}

		System.out.println("");
		System.out.println("0_return value:");
		for (String rr : cft.split("-", 0)) {
			System.out.println(rr);
		}

		System.out.println("2_return value:");
		for (String rr : cft.split("-", 2)) {
			System.out.println(rr);
		}
		System.out.println("");
		System.out.println("3_return value:");
		for (String rr : cft.split("-", 3)) {
			System.out.println(rr);
		}

	}

}

実行結果

-1_return value:
Welcome
to
arkgame.com

0_return value:
Welcome
to
arkgame.com
2_return value:
Welcome
to-arkgame.com

3_return value:
Welcome
to
arkgame.com

Java

Posted by arkgame