java.util.StringTokenizer类的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(109)

本文整理了Java中java.util.StringTokenizer类的一些代码示例,展示了StringTokenizer类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StringTokenizer类的具体详情如下:
包路径:java.util.StringTokenizer
类名称:StringTokenizer

StringTokenizer介绍

[英]Breaks a string into tokens; new code should probably use String#split.

// Legacy code: 
StringTokenizer st = new StringTokenizer("a:b:c", ":"); 
while (st.hasMoreTokens()) { 
System.err.println(st.nextToken()); 
} 
// New code: 
for (String token : "a:b:c".split(":")) { 
System.err.println(token); 
}

[中]将一个字符串拆分为标记;新代码可能应该使用字符串#split

// Legacy code: 
StringTokenizer st = new StringTokenizer("a:b:c", ":"); 
while (st.hasMoreTokens()) { 
System.err.println(st.nextToken()); 
} 
// New code: 
for (String token : "a:b:c".split(":")) { 
System.err.println(token); 
}

代码示例

代码示例来源:origin: hibernate/hibernate-orm

public static String[] split(String separators, String list, boolean include) {
  StringTokenizer tokens = new StringTokenizer( list, separators, include );
  String[] result = new String[tokens.countTokens()];
  int i = 0;
  while ( tokens.hasMoreTokens() ) {
    result[i++] = tokens.nextToken();
  }
  return result;
}

代码示例来源:origin: stanfordnlp/CoreNLP

/** Basic string tokenization, skipping over white spaces */
public static ArrayList<String> tokenize(String line) {
 ArrayList<String> tokens = new ArrayList<>();
 StringTokenizer tokenizer = new StringTokenizer(line);
 while (tokenizer.hasMoreElements()) {
  tokens.add(tokenizer.nextToken());
 }
 return tokens;
}

代码示例来源: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: org.testng/testng

public void setListeners(String listeners) {
 StringTokenizer st= new StringTokenizer(listeners, " ,");
 while(st.hasMoreTokens()) {
  m_listeners.add(st.nextToken());
 }
}

代码示例来源:origin: cmusphinx/sphinx4

protected void loadMapping(InputStream inputStream) throws IOException {
    InputStreamReader isr = new InputStreamReader(inputStream);
    BufferedReader br = new BufferedReader(isr);
    String line;
    while ((line = br.readLine()) != null) {
      StringTokenizer st = new StringTokenizer(line);
      if (st.countTokens() != 2) {
        throw new IOException("Wrong file format");
      }
      mapping.put(st.nextToken(), st.nextToken());
    }
    br.close();
    isr.close();
    inputStream.close();
  }
}

代码示例来源:origin: smuyyh/BookReader

BufferedReader hin = new BufferedReader(new InputStreamReader(
    new ByteArrayInputStream(buf, 0, rlen)));
Map<String, String> pre = new HashMap<String, String>();
InputStream bin = new FileInputStream(f.getFD());
BufferedReader in = new BufferedReader(new InputStreamReader(
    bin));
    st = new StringTokenizer(contentTypeHeader, ",; ");
    if (st.hasMoreTokens()) {
      contentType = st.nextToken();
    if (!st.hasMoreTokens()) {
      Response.error(
          outputStream,
    int read = in.read(pbuf);
    while (read >= 0 && !postLine.endsWith("\r\n")) {
      postLine += String.valueOf(pbuf, 0, read);

代码示例来源:origin: geotools/geotools

cellhead = new BufferedReader(new FileReader(cellhd));
cellhead.mark(128);
if ((line = cellhead.readLine()) == null) {
  throw new IOException(
      "The cellhead file seems to be corrupted: " + cellhd.getAbsolutePath());
            + cellhd.getAbsolutePath());
  cellhead = new BufferedReader(new FileReader(cellhd));
} else {
              new FileReader(readerGrassEnv.getCELLMISC_FORMAT()));
      while ((line = cellmiscformat.readLine()) != null) {
        StringTokenizer tokk = new StringTokenizer(line, ":");
        if (tokk.countTokens() == 2) {
          String key = tokk.nextToken().trim();
          String value = tokk.nextToken().trim();
          readerFileHeaderMap.put(key, value);

代码示例来源: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;
  }
}

代码示例来源: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: 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: stackoverflow.com

int stringTokenizer = new StringTokenizer(" " +testString + " ", ".").countTokens()-1;
System.out.println("stringTokenizer = " + stringTokenizer);

代码示例来源: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: marytts/marytts

public static String deblank(String str) {
  StringTokenizer s = new StringTokenizer(str, " ", false);
  StringBuilder strRet = new StringBuilder();
  while (s.hasMoreElements())
    strRet.append(s.nextElement());
  return strRet.toString();
}

代码示例来源:origin: libgdx/libgdx

/**
 * Returns the next token in the string as an {@code Object}. This method is
 * implemented in order to satisfy the {@code Enumeration} interface.
 *
 * @return next token in the string as an {@code Object}
 * @throws NoSuchElementException
 *                if no tokens remain.
 */
public Object nextElement() {
  return nextToken();
}

代码示例来源:origin: libgdx/libgdx

/**
 * Returns {@code true} if unprocessed tokens remain. This method is
 * implemented in order to satisfy the {@code Enumeration} interface.
 *
 * @return {@code true} if unprocessed tokens remain.
 */
public boolean hasMoreElements() {
  return hasMoreTokens();
}

代码示例来源:origin: spring-projects/spring-framework

private static Profiles parseExpression(String expression) {
  Assert.hasText(expression, () -> "Invalid profile expression [" + expression + "]: must contain text");
  StringTokenizer tokens = new StringTokenizer(expression, "()&|!", true);
  return parseTokens(expression, tokens);
}

代码示例来源: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

private double[] parseDoubleArray(String value, String key) {
 try {
  StringTokenizer tokenizer = new StringTokenizer(value);
  double[] result = new double[tokenizer.countTokens()];
  for (int i = 0; i < result.length; i++) {
   result[i] = new Double(tokenizer.nextToken()).doubleValue();
  }
  return result;
 } catch (NumberFormatException e) {
  throw createNumberFormatException("sequence of numbers", value, key);
 }
}

代码示例来源: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;
}

相关文章