本文整理了Java中java.util.StringTokenizer.<init>()
方法的一些代码示例,展示了StringTokenizer.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StringTokenizer.<init>()
方法的具体详情如下:
包路径:java.util.StringTokenizer
类名称:StringTokenizer
方法名:<init>
[英]Constructs a new StringTokenizer for the parameter string using whitespace as the delimiter. The returnDelimiters flag is set to false.
[中]使用空格作为分隔符,为参数字符串构造一个新的StringTokenizer。returnDelimiters标志设置为false。
代码示例来源:origin: stackoverflow.com
StringTokenizer tokens = new StringTokenizer(CurrentString, ":");
String first = tokens.nextToken();// this will contain "Fruit"
String second = tokens.nextToken();// this will contain " they taste good"
// in the case above I assumed the string has always that syntax (foo: bar)
// but you may want to check if there are tokens or not using the hasMoreTokens method
代码示例来源:origin: eclipse-vertx/vert.x
private static String[] tokenizePathToString(String path, String separator) {
List<String> ret = new ArrayList<>();
StringTokenizer st = new StringTokenizer(path, separator);
while (st.hasMoreTokens()) {
ret.add(st.nextToken());
}
return ret.toArray(new String[ret.size()]);
}
}
代码示例来源:origin: apache/kafka
static Version parseVersion(String versionString) {
final StringTokenizer st = new StringTokenizer(versionString, ".");
int majorVersion = Integer.parseInt(st.nextToken());
int minorVersion;
if (st.hasMoreTokens())
minorVersion = Integer.parseInt(st.nextToken());
else
minorVersion = 0;
return new Version(majorVersion, minorVersion);
}
代码示例来源:origin: javaee-samples/javaee7-samples
@Override
public void open(Serializable checkpoint) {
tokens = new StringTokenizer("1,2,3,4,5,6,7,8,9,10", ",");
// This will place the nextToken into the last batch checkpoint. Called on exception retry.
if (checkpoint != null) {
while (!Integer.valueOf(tokens.nextToken()).equals(((MyInputRecord) checkpoint).getId())) {
System.out.println("Skipping already read elements");
}
}
}
代码示例来源:origin: stackoverflow.com
int stringTokenizer = new StringTokenizer(" " +testString + " ", ".").countTokens()-1;
System.out.println("stringTokenizer = " + stringTokenizer);
代码示例来源:origin: pentaho/pentaho-kettle
public String[] getDropStrings( String str, String sep ) {
StringTokenizer strtok = new StringTokenizer( str, sep );
String[] retval = new String[ strtok.countTokens() ];
int i = 0;
while ( strtok.hasMoreElements() ) {
retval[ i ] = strtok.nextToken();
i++;
}
return retval;
}
代码示例来源:origin: Vedenin/useful-java-links
@Benchmark
public int stringTokenizer() {
// Using StringTokenizer
return new StringTokenizer(" " + testString + " ", ".").countTokens() - 1;
}
代码示例来源:origin: org.testng/testng
public void setListeners(String listeners) {
StringTokenizer st= new StringTokenizer(listeners, " ,");
while(st.hasMoreTokens()) {
m_listeners.add(st.nextToken());
}
}
代码示例来源:origin: javaee-samples/javaee7-samples
@Override
public Person processItem(Object t) {
System.out.println("processItem: " + t);
StringTokenizer tokens = new StringTokenizer((String) t, ",");
String name = tokens.nextToken();
String date;
try {
date = tokens.nextToken();
format.setLenient(false);
format.parse(date);
} catch (ParseException e) {
return null;
}
return new Person(id++, name, date);
}
}
代码示例来源:origin: hankcs/HanLP
public static LinkedList<String> readLineList(String path)
{
LinkedList<String> result = new LinkedList<String>();
String txt = readTxt(path);
if (txt == null) return result;
StringTokenizer tokenizer = new StringTokenizer(txt, "\n");
while (tokenizer.hasMoreTokens())
{
result.add(tokenizer.nextToken());
}
return result;
}
代码示例来源:origin: org.testng/testng
/**
* Splits the given String s into tokens where the separator is
* either the space character or the comma character. For example,
* if s is "a,b, c" this method returns {"a", "b", "c"}
*
* @param s the string to split
* @return the split token
*
* @deprecated Unused
*/
@Deprecated
public static String[] stringToArray(String s) {
// TODO CQ would s.split() be a better way of doing this?
StringTokenizer st = new StringTokenizer(s, " ,");
String[] result = new String[st.countTokens()];
for (int i = 0; i < result.length; i++) {
result[i] = st.nextToken();
}
return result;
}
代码示例来源:origin: spring-projects/spring-framework
public static void reset() {
String s = "UK 123";
StringTokenizer st = new StringTokenizer(s);
property = st.nextToken();
}
}
代码示例来源:origin: Vedenin/useful-java-links
@Benchmark
public int stringTokenizer() {
// Using StringTokenizer
return new StringTokenizer(" " + testString + " ", ".").countTokens() - 1;
}
代码示例来源:origin: org.testng/testng
public void setMethodSelectors(String methodSelectors) {
StringTokenizer st= new StringTokenizer(methodSelectors, " ,");
while(st.hasMoreTokens()) {
m_methodselectors.add(st.nextToken());
}
}
代码示例来源:origin: plantuml/plantuml
public static NumberAnalyzed2 load(String name, Preferences prefs) {
final String value = prefs.get(name + ".saved", "");
if (value.length() == 0) {
System.err.println("Cannot load " + name);
return null;
}
try {
final StringTokenizer st = new StringTokenizer(value, ";");
return new NumberAnalyzed2(name, Long.parseLong(st.nextToken(), 36), Long.parseLong(st.nextToken(), 36),
Long.parseLong(st.nextToken(), 36), Long.parseLong(st.nextToken(), 36), Long.parseLong(
st.nextToken(), 36), Long.parseLong(st.nextToken(), 36));
} catch (Exception e) {
e.printStackTrace();
Log.info("Error reading " + value);
return null;
}
}
代码示例来源:origin: log4j/log4j
/**
* Set a string representing the property name/value pairs.
*
* Form: propname1=propvalue1,propname2=propvalue2
*
* @param props
*/
public void setProperties(String props) {
Map hashTable = new HashMap();
StringTokenizer pairs = new StringTokenizer(props, ",");
while (pairs.hasMoreTokens()) {
StringTokenizer entry = new StringTokenizer(pairs.nextToken(), "=");
hashTable.put(entry.nextElement().toString().trim(), entry.nextElement().toString().trim());
}
synchronized(this) {
properties = hashTable;
}
}
代码示例来源:origin: org.apache.ant/ant
/**
* Splits the string on every token into an array of strings.
*
* @param string the string
* @param onToken the token
* @return the resultant array
*/
private static String[] split(final String string,
final String onToken) {
final StringTokenizer tokenizer = new StringTokenizer(string, onToken);
final String[] result = new String[tokenizer.countTokens()];
for (int i = 0; i < result.length; i++) {
result[i] = tokenizer.nextToken();
}
return result;
}
代码示例来源:origin: libgdx/libgdx
private static FileHandle getRelativeFileHandle (FileHandle file, String path) {
StringTokenizer tokenizer = new StringTokenizer(path, "\\/");
FileHandle result = file.parent();
while (tokenizer.hasMoreElements()) {
String token = tokenizer.nextToken();
if (token.equals(".."))
result = result.parent();
else {
result = result.child(token);
}
}
return result;
}
代码示例来源:origin: libgdx/libgdx
public static String[] tokenizeToStringArray (String str, String delimiters, boolean trimTokens, boolean ignoreEmptyTokens) {
if (str == null) {
return null;
}
StringTokenizer st = new StringTokenizer(str, delimiters);
List<String> tokens = new ArrayList<String>();
while (st.hasMoreTokens()) {
String token = st.nextToken();
if (trimTokens) {
token = token.trim();
}
if (!ignoreEmptyTokens || token.length() > 0) {
tokens.add(token);
}
}
return tokens.toArray(new String[tokens.size()]);
}
代码示例来源:origin: JetBrains/ideavim
private int getMaxSegmentLength(@NotNull String text) {
final StringTokenizer tokenizer = new StringTokenizer(text, "\n");
int maxLen = 0;
while (tokenizer.hasMoreTokens()) {
final String s = tokenizer.nextToken();
maxLen = Math.max(s.length(), maxLen);
}
return maxLen;
}
内容来源于网络,如有侵权,请联系作者删除!