parserutils.java
来自「《深入浅出设计模式》的完整源代码」· Java 代码 · 共 46 行
JAVA
46 行
//this is our first class which does not have a main//method. Its purpose it to serve as a warehouse of //related methods that can be accessed from any main//method.//This class contains methods useful for writing a parser.// 1. public static String getKeyInput(){// blocks program until user enters zero or// more characters followed by a "enter"// and returns input to calling program// 2. public static String[] getTokens(String input){// takes String and breaks into tokens defined// by one or more white spaces and return array// of String each element of which is an individual// tokenpackage UsingPlastic;import java.io.*;import java.util.*;class ParserUtils{ public static String getKeyInput(){ String input = null; try{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); input = in.readLine(); } catch (IOException ioe){ System.out.println(ioe); } return input; } public static String[] getTokens(String input){ int i = 0; StringTokenizer st = new StringTokenizer(input); int numTokens = st.countTokens(); String[] tokenList = new String[numTokens]; while (st.hasMoreTokens()){ tokenList[i] = st.nextToken(); i++; } return(tokenList); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?