forked from TimSongCoder/LearnJavaForAndroid
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTokenize.java
More file actions
20 lines (19 loc) · 704 Bytes
/
Copy pathTokenize.java
File metadata and controls
20 lines (19 loc) · 704 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import java.util.StringTokenizer;
public class Tokenize{
public static void main(String[] args){
String source = "03-12-2014 03:05:20";
StringTokenizer tokenizer = new StringTokenizer(source, "- :"); // second parameter specifies the delimiters, character by character.
String[] tokens = new String[tokenizer.countTokens()];
int i = 0;
while(tokenizer.hasMoreTokens()){
tokens[i] = tokenizer.nextToken();
i++;
}
System.out.println("month: " + tokens[0]);
System.out.println("day: " + tokens[1]);
System.out.println("year: " + tokens[2]);
System.out.println("hour: " + tokens[3]);
System.out.println("minute: " + tokens[4]);
System.out.println("second: " + tokens[5]);
}
}