Android 中StringTokenizer 实现字符串分割
StringTokenizer 实现字符串分割
1. java.util.StringTokenizer 用于分割字符串
实例一:
String str = "abc-de" ;
StringTokenizer st = new StringTokenizer (str , "-") ;
System.out.println( st.nextToKen() ) ;
System.out.println( st.nextToKen() ) ;
输出:
abc
de
2.用String的split() ;来分割字符串,返回一个字符串数组
实例二:
- package com.struts2.bean;
- public class test {
- public static void main(String[] args)
- {
- String str = "abc-d";
- String[] s = str.split("-");
- for(int i = 0 ; i < s.length ; i++)
- {
- System.out.println(s[i]);
- }
- }
- }
输出:
abc
d