jaroslav@597: /*
jaroslav@597: * Copyright (c) 1994, 2004, Oracle and/or its affiliates. All rights reserved.
jaroslav@597: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jaroslav@597: *
jaroslav@597: * This code is free software; you can redistribute it and/or modify it
jaroslav@597: * under the terms of the GNU General Public License version 2 only, as
jaroslav@597: * published by the Free Software Foundation. Oracle designates this
jaroslav@597: * particular file as subject to the "Classpath" exception as provided
jaroslav@597: * by Oracle in the LICENSE file that accompanied this code.
jaroslav@597: *
jaroslav@597: * This code is distributed in the hope that it will be useful, but WITHOUT
jaroslav@597: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jaroslav@597: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jaroslav@597: * version 2 for more details (a copy is included in the LICENSE file that
jaroslav@597: * accompanied this code).
jaroslav@597: *
jaroslav@597: * You should have received a copy of the GNU General Public License version
jaroslav@597: * 2 along with this work; if not, write to the Free Software Foundation,
jaroslav@597: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jaroslav@597: *
jaroslav@597: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jaroslav@597: * or visit www.oracle.com if you need additional information or have any
jaroslav@597: * questions.
jaroslav@597: */
jaroslav@597:
jaroslav@597: package java.util;
jaroslav@597:
jaroslav@597: import java.lang.*;
jaroslav@597:
jaroslav@597: /**
jaroslav@597: * The string tokenizer class allows an application to break a
jaroslav@597: * string into tokens. The tokenization method is much simpler than
jaroslav@597: * the one used by the StreamTokenizer class. The
jaroslav@597: * StringTokenizer methods do not distinguish among
jaroslav@597: * identifiers, numbers, and quoted strings, nor do they recognize
jaroslav@597: * and skip comments.
jaroslav@597: *
jaroslav@597: * The set of delimiters (the characters that separate tokens) may
jaroslav@597: * be specified either at creation time or on a per-token basis.
jaroslav@597: *
jaroslav@597: * An instance of StringTokenizer behaves in one of two
jaroslav@597: * ways, depending on whether it was created with the
jaroslav@597: * returnDelims flag having the value true
jaroslav@597: * or false:
jaroslav@597: *
jaroslav@597: *
If the flag is false, delimiter characters serve to
jaroslav@597: * separate tokens. A token is a maximal sequence of consecutive
jaroslav@597: * characters that are not delimiters.
jaroslav@597: *
If the flag is true, delimiter characters are themselves
jaroslav@597: * considered to be tokens. A token is thus either one delimiter
jaroslav@597: * character, or a maximal sequence of consecutive characters that are
jaroslav@597: * not delimiters.
jaroslav@597: *
jaroslav@597: * A StringTokenizer object internally maintains a current
jaroslav@597: * position within the string to be tokenized. Some operations advance this
jaroslav@597: * current position past the characters processed.
jaroslav@597: * A token is returned by taking a substring of the string that was used to
jaroslav@597: * create the StringTokenizer object.
jaroslav@597: *
jaroslav@597: * The following is one example of the use of the tokenizer. The code:
jaroslav@597: *
jaroslav@597: * StringTokenizer st = new StringTokenizer("this is a test");
jaroslav@597: * while (st.hasMoreTokens()) {
jaroslav@597: * System.out.println(st.nextToken());
jaroslav@597: * }
jaroslav@597: *
jaroslav@597: *
jaroslav@597: * prints the following output:
jaroslav@597: *
jaroslav@597: * this
jaroslav@597: * is
jaroslav@597: * a
jaroslav@597: * test
jaroslav@597: *
jaroslav@597: *
jaroslav@597: *
jaroslav@597: * StringTokenizer is a legacy class that is retained for
jaroslav@597: * compatibility reasons although its use is discouraged in new code. It is
jaroslav@597: * recommended that anyone seeking this functionality use the split
jaroslav@597: * method of String or the java.util.regex package instead.
jaroslav@597: *
jaroslav@597: * The following example illustrates how the String.split
jaroslav@597: * method can be used to break up a string into its basic tokens:
jaroslav@597: *
jaroslav@597: * String[] result = "this is a test".split("\\s");
jaroslav@597: * for (int x=0; x<result.length; x++)
jaroslav@597: * System.out.println(result[x]);
jaroslav@597: *
jaroslav@597: *
jaroslav@597: * prints the following output:
jaroslav@597: *
jaroslav@597: * this
jaroslav@597: * is
jaroslav@597: * a
jaroslav@597: * test
jaroslav@597: *