In the JavaIO tutorial, we will learn how to use StringTokenizer to parse words from a String. This class is not from a IO package but worth learning it when we talk about Streams.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
private void btnGetWordsActionPerformed(java.awt.event.ActionEvent evt) { //Sample 011.01: Get Text and Give it to Tokenizer String strInput = taInput.getText(); StringTokenizer tokenizer = new StringTokenizer(strInput); //Sample 011.2: Use Tokenizer to get the words while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); taOutput.append(token + "\n"); } } |
- Java IO – Formatted Output via PrintWriter Example
- Java IO | StreamTokenizer Parsing Numbers & Words
Categories: Java-Tube