我已经编写了代码来吐出字符串,即出生日期,我想将它存储在 3 个不同的变量中,如何做到这一点。 (Mday=1,Mmonth=1,MYear=2011)。我正在动态获取生日。而且我正在获取 token 中的值。
StringTokenizer st = new StringTokenizer(BirtDate, "/");
while (st.hasMoreElements()) {
String token = st.nextToken();
System.out.println("Token = " + token);
}
最佳答案
StringTokenizer is a legacy class that is retained for compatibility reasons although its use is discouraged in new code. It is recommended that anyone seeking this functionality use the split method of String or the java.util.regex package instead
参见http://docs.oracle.com/javase/6/docs/api/java/util/StringTokenizer.html
使用代替
String[] token = BirtDate.split("/")
关于java - 从字符串标记器获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13177401/