本文整理了Java中java.util.StringTokenizer.nextToken()
方法的一些代码示例,展示了StringTokenizer.nextToken()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StringTokenizer.nextToken()
方法的具体详情如下:
包路径:java.util.StringTokenizer
类名称:StringTokenizer
方法名:nextToken
[英]Returns the next token in the string as a String.
[中]以字符串形式返回字符串中的下一个标记。
代码示例来源: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 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: 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: prestodb/presto
Rule(StringTokenizer st) {
if (st.countTokens() < 6) {
throw new IllegalArgumentException("Attempting to create a Rule from an incomplete tokenizer");
}
iName = st.nextToken().intern();
iFromYear = parseYear(st.nextToken(), 0);
iToYear = parseYear(st.nextToken(), iFromYear);
if (iToYear < iFromYear) {
throw new IllegalArgumentException();
}
iType = parseOptional(st.nextToken());
iDateTimeOfYear = new DateTimeOfYear(st);
iSaveMillis = parseTime(st.nextToken());
iLetterS = parseOptional(st.nextToken());
}
代码示例来源: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 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: 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: 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: spring-projects/spring-framework
public static void reset() {
String s = "UK 123";
StringTokenizer st = new StringTokenizer(s);
property = st.nextToken();
}
}
代码示例来源:origin: joda-time/joda-time
Rule(StringTokenizer st) {
if (st.countTokens() < 6) {
throw new IllegalArgumentException("Attempting to create a Rule from an incomplete tokenizer");
}
iName = st.nextToken().intern();
iFromYear = parseYear(st.nextToken(), 0);
iToYear = parseYear(st.nextToken(), iFromYear);
if (iToYear < iFromYear) {
throw new IllegalArgumentException();
}
iType = parseOptional(st.nextToken());
iDateTimeOfYear = new DateTimeOfYear(st);
iSaveMillis = parseTime(st.nextToken());
iLetterS = parseOptional(st.nextToken());
}
代码示例来源: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: 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: spring-projects/spring-framework
private String encodeIfNecessary(String path, @Nullable HttpServletRequest request, Resource location) {
if (shouldEncodeRelativePath(location) && request != null) {
Charset charset = this.locationCharsets.getOrDefault(location, StandardCharsets.UTF_8);
StringBuilder sb = new StringBuilder();
StringTokenizer tokenizer = new StringTokenizer(path, "/");
while (tokenizer.hasMoreTokens()) {
String value = UriUtils.encode(tokenizer.nextToken(), charset);
sb.append(value);
sb.append("/");
}
if (!path.endsWith("/")) {
sb.setLength(sb.length() - 1);
}
return sb.toString();
}
else {
return path;
}
}
代码示例来源: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: JodaOrg/joda-time
Rule(StringTokenizer st) {
if (st.countTokens() < 6) {
throw new IllegalArgumentException("Attempting to create a Rule from an incomplete tokenizer");
}
iName = st.nextToken().intern();
iFromYear = parseYear(st.nextToken(), 0);
iToYear = parseYear(st.nextToken(), iFromYear);
if (iToYear < iFromYear) {
throw new IllegalArgumentException();
}
iType = parseOptional(st.nextToken());
iDateTimeOfYear = new DateTimeOfYear(st);
iSaveMillis = parseTime(st.nextToken());
iLetterS = parseOptional(st.nextToken());
}
代码示例来源: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: spring-projects/spring-framework
@Override
@Nullable
public String[] getParameterNames(Method method) {
if (method.getParameterCount() == 0) {
return new String[0];
}
AspectJAnnotation<?> annotation = findAspectJAnnotationOnMethod(method);
if (annotation == null) {
return null;
}
StringTokenizer nameTokens = new StringTokenizer(annotation.getArgumentNames(), ",");
if (nameTokens.countTokens() > 0) {
String[] names = new String[nameTokens.countTokens()];
for (int i = 0; i < names.length; i++) {
names[i] = nameTokens.nextToken();
}
return names;
}
else {
return null;
}
}
内容来源于网络,如有侵权,请联系作者删除!