StringTokenizer tokenizer = new StringTokenizer (number, ",");
boolean bool = true;
while (Tokenizer.hasmoretokens ()) {
try {
Double.valueof (Tokenizer.nexttoken ());
catch (Exception e) {
bool = false;
}
}
How to convert a string to an array
int gv[];
int i = 0;
StringTokenizer tokenizer = new StringTokenizer (Goodsvolume, ",,");
GV = new Int[tokenizer.counttokens ()];//dynamically determines the length of an array
while (Tokenizer.hasmoretokens ()) {
String d = Tokenizer.nexttoken ();
Gv[i] = integer.valueof (d);//convert string to integral type
i++;
}
String parsing
Private string[] Stringanalytical (String str, string Divisionchar) {
String string[];
int i = 0;
StringTokenizer tokenizer = new StringTokenizer (str, divisionchar);
string = new String[tokenizer.counttokens ()];//dynamically determines the length of an array
while (Tokenizer.hasmoretokens ()) {
String[i] = new String ();
String[i] = Tokenizer.nexttoken ();
i++;
}
Return string;//returns an array of strings
}
int Counttokens ()
Calculates the number of times the Nexttoken method of this tokenizer can be called before an exception is generated.
Boolean hasmoreelements ()
Returns the same value as the Hasmoretokens method.
Boolean Hasmoretokens ()
Test if there are more available tags in this tokenizer string.
Object nextelement ()
It returns the same value as the Nexttoken method, except that its declared return value is Object instead of String.
String Nexttoken ()
Returns the next token for this string tokenizer.
String Nexttoken (String Delim)
Returns the next token in the string Tokenizer this string.
public class Stringanalytical {
string parsing, converting strings to string arrays based on delimiters
Private string[] Stringanalytical (string string, char c) {
int i = 0;
int count = 0;
if (String.IndexOf (c) = =-1)
return new string[] {String};//returns the character itself if no delimiter is included
Char[] cs = String.tochararray ();
int length = Cs.length;
for (i = 1; i < length-1 i++) {//filter out the first and last delimiters
if (cs[i] = = c) {
count++;//get the number of delimiters
}
}
string[] Strarray = new String[count + 1];
int k = 0, j = 0;
string str = string;
if (k = Str.indexof (c)) = = 0)//Remove the first character from the separator
str = str.substring (k + 1);
if (Str.indexof (c) = =-1)//check for delimiters, return string if not included
return new string[] {str};
while ((k = Str.indexof (c))!=-1) {//string contains a separator
Strarray[j++] = str.substring (0, k);
str = str.substring (k + 1);
if ((k = Str.indexof (c)) = = 1 && str.length () > 0)
Strarray[j++] = str.substring (0);
}
return strarray;
}
public void Printstring (string[] s) {
System.out.println ("*********************************");
for (String str:s)
System.out.println (str);
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service