本文整理了Java中java.util.StringTokenizer.countTokens()
方法的一些代码示例,展示了StringTokenizer.countTokens()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StringTokenizer.countTokens()
方法的具体详情如下:
包路径:java.util.StringTokenizer
类名称:StringTokenizer
方法名:countTokens
[英]Returns the number of unprocessed tokens remaining in the string.
[中]返回字符串中剩余的未处理令牌数。
代码示例来源: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: 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: Impetus/Kundera
if (new StringTokenizer(name, ".").countTokens() > 1)
rowList.add(valueInBytes);
代码示例来源: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: Vedenin/useful-java-links
@Benchmark
public int stringTokenizer() {
// Using StringTokenizer
return new StringTokenizer(" " + testString + " ", ".").countTokens() - 1;
}
代码示例来源:origin: hibernate/hibernate-orm
public static String[] splitTrimmingTokens(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().trim();
}
return result;
}
代码示例来源: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: 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: Vedenin/useful-java-links
@Benchmark
public int stringTokenizer() {
// Using StringTokenizer
return new StringTokenizer(" " + testString + " ", ".").countTokens() - 1;
}
代码示例来源:origin: apache/flink
@Override
public int compare(String o1, String o2) {
StringTokenizer st1 = new StringTokenizer(o1, "|");
StringTokenizer st2 = new StringTokenizer(o2, "|");
if (st1.countTokens() != st2.countTokens()) {
return st1.countTokens() - st2.countTokens();
}
// first token is ID
String t1 = st1.nextToken();
String t2 = st2.nextToken();
if (!t1.equals(t2)) {
return t1.compareTo(t2);
}
while (st1.hasMoreTokens()) {
t1 = st1.nextToken();
t2 = st2.nextToken();
double d1 = Double.parseDouble(t1);
double d2 = Double.parseDouble(t2);
if (Math.abs(d1 - d2) > maxDelta) {
return d1 < d2 ? -1 : 1;
}
}
return 0;
}
};
代码示例来源: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: 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: jenkinsci/jenkins
/**
* Builds a list of {@link Path} that represents ancestors
* from a string like "/foo/bar/zot".
*/
private List<Path> buildParentPath(String pathList, int restSize) {
List<Path> r = new ArrayList<Path>();
StringTokenizer tokens = new StringTokenizer(pathList, "/");
int total = tokens.countTokens();
int current=1;
while(tokens.hasMoreTokens()) {
String token = tokens.nextToken();
r.add(new Path(createBackRef(total-current+restSize),token,true,0, true,0));
current++;
}
return r;
}
代码示例来源: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: apache/hive
String[] split(String line, String delim) {
StringTokenizer tok = new StringTokenizer(line, delim);
String[] ret = new String[tok.countTokens()];
int index = 0;
while (tok.hasMoreTokens()) {
String t = tok.nextToken();
t = dequote(t);
ret[index++] = t;
}
return ret;
}
代码示例来源: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: org.apache.commons/commons-collections4
/**
* Override toList(Enumeration) for StringTokenizer as it implements Enumeration<Object>
* for the sake of backward compatibility.
*
* @param stringTokenizer the tokenizer to convert to a {@link List}<{@link String}>
* @return a list containing all tokens of the given StringTokenizer
*/
public static List<String> toList(final StringTokenizer stringTokenizer) {
final List<String> result = new ArrayList<>(stringTokenizer.countTokens());
while (stringTokenizer.hasMoreTokens()) {
result.add(stringTokenizer.nextToken());
}
return result;
}
}
代码示例来源:origin: log4j/log4j
/** @see DefaultHandler **/
public void endElement(String aNamespaceURI,
String aLocalName,
String aQName)
{
if (TAG_EVENT.equals(aQName)) {
addEvent();
resetData();
} else if (TAG_NDC.equals(aQName)) {
mNDC = mBuf.toString();
} else if (TAG_MESSAGE.equals(aQName)) {
mMessage = mBuf.toString();
} else if (TAG_THROWABLE.equals(aQName)) {
final StringTokenizer st =
new StringTokenizer(mBuf.toString(), "\n\t");
mThrowableStrRep = new String[st.countTokens()];
if (mThrowableStrRep.length > 0) {
mThrowableStrRep[0] = st.nextToken();
for (int i = 1; i < mThrowableStrRep.length; i++) {
mThrowableStrRep[i] = "\t" + st.nextToken();
}
}
}
}
代码示例来源:origin: debezium/debezium
/**
* Split a string into pieces based on delimiters. Similar to the Perl function of the same name. The delimiters are not
* included in the returned strings.
*
* @param str Full string
* @param splitter Characters to split on
* @return List of String pieces from full string
*/
private static List<String> split(String str,
String splitter) {
StringTokenizer tokens = new StringTokenizer(str, splitter);
ArrayList<String> l = new ArrayList<>(tokens.countTokens());
while (tokens.hasMoreTokens()) {
l.add(tokens.nextToken());
}
return l;
}
内容来源于网络,如有侵权,请联系作者删除!