「Java」splitメソッドを用いるサンプル

書式
文字列.split(区切文字)
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
package com.arkgame.study;
public class SplitDemo {
private static final String ptn = "[?&]";
public static void main(String[] args) {
String target = "create.jsp?user=yamada&pwd=6688";
String[] results = target.split(ptn);
for (String res : results) {
System.out.println("結果:" + res);
}
}
}
package com.arkgame.study; public class SplitDemo { private static final String ptn = "[?&]"; public static void main(String[] args) { String target = "create.jsp?user=yamada&pwd=6688"; String[] results = target.split(ptn); for (String res : results) { System.out.println("結果:" + res); } } }
package com.arkgame.study;

public class SplitDemo {

      private static final String ptn = "[?&]";

      public static void main(String[] args) {
            String target = "create.jsp?user=yamada&pwd=6688";
            String[] results = target.split(ptn);
            for (String res : results) {
                  System.out.println("結果:" + res);
            }
      }

}

実行結果
結果:create.jsp
結果:user=yamada
結果:pwd=6688

Java

Posted by arkgame