https://docs.oracle.com/javase/8/docs/api/
StringTokenizer는 3가지의 생성자를 갖는다.
StringTokenizer(String str)
문자열 공백문자(\t,\n,\r,\f)를 구획문자로 가진다. |
StringTokenizer(String str, String delim)
문자열 + 구획문자 |
StringTokenizer(String str, String delim, boolean returnDelims)
문자열 + 구획문자 + 구획문자를 문자열에포함유무 returnDelims은 기본값은 false로 설정되고 true일경우 구획문자도 토큰으로 간주한다. |
Modifier and TypeMethod and Description
int | countTokens()
토큰의 갯수, 구획문자로 구분된 토큰 갯수를 리턴한다. |
boolean | hasMoreElements()
hasMoreTokens()와 같은 값을 리턴하고 Enumeration인터페이스를 구현할 수 있도록 존재한다. Enumeration은 객체가 적어도 1개 이상의 요소를 포함하는 경우에는 true 그렇지 않은경우는 false를 반환한다. |
boolean | hasMoreTokens()
현재의 위치의 뒤에 적어도 1개의 토큰이 존재하는 경우 True를 반환하고 그렇지 않으면 false를 반환한다. |
Object | nextElement()
nextToken()과 같은 값을 반환하고 Enumeration인터페이스를 구현할 수 있도록 존재한다. |
String | nextToken()
현재위치 이후의 문자열에서 구획문자를 통해 잘랐던 값을 전달한다. |
String | nextToken(String delim)
구획문자를 통해 입력받은 값을 자르고 전달하고 delim에 들어있는 구획문자로 변경하여 자른 값을 전달한다. |
사용예시
StringTokenizer st = new StringTokenizer("this is a test"); while (st.hasMoreTokens()) { System.out.println(st.nextToken()); }
prints the following output:
this
is
a
test
The following example illustrates how the String.split method can be used to break up a string into its basic tokens:
String[] result = "this is a test".split("\\s"); for (int x=0; x<result.length; x++) System.out.println(result[x]);
prints the following output:
this
is
a
test
'2019백업' 카테고리의 다른 글
JAVA-ArrayList (0) | 2019.03.29 |
---|---|
JAVA-Vector (0) | 2019.03.29 |
JAVA-java.util.* (Date,Calendar,StringTokenizer,ArrayList,HashMap) (0) | 2019.03.29 |
JAVA - StringBuffer, StringBuilder 차이점 (0) | 2019.03.29 |
자바-String클래스 (0) | 2019.03.29 |