자바기초(StringTokenizer)

bitna's study note·2022년 5월 4일
0

자바

목록 보기
69/119

5월 3일 내용정리

-hasMoreElements 남아있는 토큰의 여부를 boolean으로 반환
-변수명.countTokens 토큰갯수
-hasMoreElements 남아있는 토큰이 true면 nextToken()로 다음 토큰을 꺼낸다.

package study_0503;

import java.util.StringTokenizer;

public class TokenExam {

	public static void main(String[] args) {
		String s="of the people, by the people, for the people";
		
		StringTokenizer st =new StringTokenizer(s," "); 
		System.out.println(st.countTokens());
		
		StringTokenizer st01 =new StringTokenizer(s,","); 
		System.out.println(st.countTokens());
		
		while(st.hasMoreElements()) { //hasMoreElements 남아있는 토큰의 여부를 boolean으로 반환
			System.out.print(st.nextToken()+"/"); //hasMoreElements남아있는 토큰이 true면 nextToken()로 다음 토큰을 꺼낸다. 
		}

	}
profile
좋은개발자가 되기위한 삽질기록 노트

0개의 댓글