文档章节

StringTokenizer用法讲解

qwweeezhengwei
 qwweeezhengwei
发布于 2017/08/02 11:15
字数 457
阅读 1
收藏 0

StringTokenizer是JDK1.0提供

看看当前类上面的描述:

/**
 * The string tokenizer class allows an application to break a
 * string into tokens. The tokenization method is much simpler than
 * the one used by the <code>StreamTokenizer</code> class. The
 * <code>StringTokenizer</code> methods do not distinguish among
 * identifiers, numbers, and quoted strings, nor do they recognize
 * and skip comments.
 * <p>
 * The set of delimiters (the characters that separate tokens) may
 * be specified either at creation time or on a per-token basis.
 * <p>
 * An instance of <code>StringTokenizer</code> behaves in one of two
 * ways, depending on whether it was created with the
 * <code>returnDelims</code> flag having the value <code>true</code>
 * or <code>false</code>:
 * <ul>
 * <li>If the flag is <code>false</code>, delimiter characters serve to
 *     separate tokens. A token is a maximal sequence of consecutive
 *     characters that are not delimiters.
 * <li>If the flag is <code>true</code>, delimiter characters are themselves
 *     considered to be tokens. A token is thus either one delimiter
 *     character, or a maximal sequence of consecutive characters that are
 *     not delimiters.
 * </ul><p>
 * A <tt>StringTokenizer</tt> object internally maintains a current
 * position within the string to be tokenized. Some operations advance this
 * current position past the characters processed.<p>
 * A token is returned by taking a substring of the string that was used to
 * create the <tt>StringTokenizer</tt> object.
 * <p>
 * The following is one example of the use of the tokenizer. The code:
 * <blockquote><pre>
 *     StringTokenizer st = new StringTokenizer("this is a test");
 *     while (st.hasMoreTokens()) {
 *         System.out.println(st.nextToken());
 *     }
 * </pre></blockquote>
 * <p>
 * prints the following output:
 * <blockquote><pre>
 *     this
 *     is
 *     a
 *     test
 * </pre></blockquote>
 *
 * <p>
 * <tt>StringTokenizer</tt> is a legacy class that is retained for
 * compatibility reasons although its use is discouraged in new code. It is
 * recommended that anyone seeking this functionality use the <tt>split</tt>
 * method of <tt>String</tt> or the java.util.regex package instead.
 * <p>
 * The following example illustrates how the <tt>String.split</tt>
 * method can be used to break up a string into its basic tokens:
 * <blockquote><pre>
 *     String[] result = "this is a test".split("\\s");
 *     for (int x=0; x&lt;result.length; x++)
 *         System.out.println(result[x]);
 * </pre></blockquote>
 * <p>
 * prints the following output:
 * <blockquote><pre>
 *     this
 *     is
 *     a
 *     test
 * </pre></blockquote>
 *
 * @author  unascribed
 * @see     java.io.StreamTokenizer
 * @since   JDK1.0
 */

在上面的描述中明确说明,StringTokenizer 是出于兼容性的原因而被保留的遗留类(虽然在新代码中并不鼓励使用它)。建议所有寻求此功能的人使用 String 的 split 方法或 Java.util.regex 包。

 

© 著作权归作者所有

qwweeezhengwei
粉丝 0
博文 13
码字总数 31124
作品 0
成都
私信 提问
StringTokenizer的用法:如何使用指定的字符串分割另一个字符串

RT,例如使用"java"字符串分割另一个"abc jkv java ikle",我希望得到"abc jkv "和" ikle"两个字符串。 StringTokenizer st = new StringTokenizer("abc jkv java ikle", "java"); while(st.......

浣雨笑笑生
2014/07/27
1K
2
StringTokenizer类的使用

StringTokenizer是一个用来分隔String的应用类,相当于VB的split函数。 1.构造函数 public StringTokenizer(String str) public StringTokenizer(String str, String delim) public StringT......

木子木
2014/03/27
20
0
StringTokenizer(字符串分隔解析类型) java.util.StringTokeniz

功效:将字符串以定界符为界,分析为一个个的token(可理解为单词),定界符可以自己指定。 构造函数。 StringTokenizer(String str) :构造一个用来解析str的StringTokenizer对象。java默认的...

SZL
2014/03/22
110
0
Split()拆分字符串与StringTokenizer拆分字符串

前言 不管用何种编程语言写代码,对字符串的处理都是必不可少的,其中对字符串的拆分在许多场合都频繁用到。 今天介绍Java中两种主流的拆分方法,一是lang包String类的split()方法,另一种则是...

绝地逢生
2018/11/14
30
0
hadoop 多个maper处理

package com.smilezl.learn.CalWord; import java.io.IOException; import java.util.StringTokenizer; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; i......

smilezhuolin
2018/07/03
0
0

没有更多内容

加载失败,请刷新页面

加载更多

skywalking(容器部署)

skywalking(容器部署) 标签(空格分隔): APM [toc] 1. Elasticsearch SkywalkingElasticsearch 5.X(部分功能报错、拓扑图不显示) Skywalking需要Elasticsearch 6.X docker network create......

JUKE
19分钟前
4
0
解决Unable to find a single main class from the following candidates [xxx,xxx]

一、问题描述 1.1 开发环境配置 pom.xml <plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><!--一定要对上springboot版本号,因......

TeddyIH
19分钟前
4
0
Dubbo服务限制大数据传输抛Data length too large: 13055248, max payload: 8388608解决方案

当dubbo服务提供者向消费层传输大数据容量数据时,会受到Dubbo的限制,报类似如下异常: 2019-08-23 11:04:31.711 [ DubboServerHandler-XX.XX.XX.XXX:20880-thread-87] - [ ERROR ] [com.al...

huangkejie
23分钟前
4
0
HashMap和ConcurrentHashMap的区别

为了线程安全,ConcurrentHashMap 引入了一个 “分段锁” 的概念。具体可以理解把一个大的 map 拆分成 N 个小的 Map 。最后再根据 key.hashcode( )来决定放到哪一个 hashmap 中去。 hashmap ...

Garphy
23分钟前
3
0
购买SSL证书需要注意哪些问题

为了保障网站的基本安全,为网站部署SSL证书,已经是一种常态了。各大浏览器对于安装了SSL证书的网站会更友好,并且不会发出“不安全”的提示。部署SSL证书之前首先得去给网站购买一个SSL证书...

安信证书
53分钟前
6
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部