java, split과 tokenizer의 차이점

 
String str = "홍길동--2001/03/14-서울시";
String split[] = str.split("-");
for (int i = 0; i < split.length; i++) {
    System.out.println("split[" + i + "] = " + split[i]);
}

 

>>차이점 

* split : null 문자를 같은 데이터 인정

* StringTokenizer : null문자를 같은 데이터 인정하지 않음 

StringTokenizer st = new StringTokenizer(str, "-");
        
int len = st.countTokens();
System.out.println("len = " + len);

System.out.println(st.nextToken());
System.out.println(st.nextToken());
System.out.println(st.nextToken());

    
st = new StringTokenizer(str, "-");

String name = st.nextToken();
int age = Integer.parseInt(st.nextToken());
String birth = st.nextToken();
String address = st.nextToken();

System.out.println(name + " " + age + " " + birth + " " + address);