「Java」split()で文字列を分割するサンプル

サンプルコード

package com.example;

public class SplitDemo {

      public static void main(String[] args) {

            String str = "11A,11AA,11AAA";
            String ss = ",";
            String[] cft = str.split(ss);
            if (cft.length == 3) {
                  System.out.println(cft[0]);
                  System.out.println(cft[1]);
                  System.out.println(cft[2]);
            } else {
                  System.out.println("no exist");
            }
      }

}

結果
11A
11AA
11AAA

Java

Posted by arkgame