java:a part:
java.util.Vector v = new Vector();//store the data
java.lang.String str = new String();//get the data from system input
char id = YOUR_NEED;//the character which be used to
str = System.in.readLine();
while( str != null){
}
java.util.Vector v = new Vector();//store the data
java.lang.String str = new String();//get the data from system input
char id = YOUR_NEED;//the character which be used to
str = System.in.readLine();
while( str != null){
}
java.util.Vector v = new Vector();//store the data
java.lang.String str = new String();//get the data from system input
//the character which be used to dispart the data
char id = YOUR_NEED;
str = System.in.readLine();
String ss = new String();//the temp string
int pos = 0;//the position where the id come
while( str != null){
pos = str.indexOf(id);
while( pos > 0 );
v.add(new String(str.subString( 0,pos - 1 )));
str = str.subString(pos+1,str.length());
}
v.add(new String(str));
}..........try it!
import java.util.StringTokenizer;
import java.io.*;
public class TokenTest
{
public static void main(String[] args)
{
System.out.println("input your words...");
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
while(true)
{
String s="";
try
{
s=in.readLine();
}catch(IOException e){}
StringTokenizer st=new StringTokenizer(s);
int c=st.countTokens();
String[] s2=new String[c];
//开始存入数组
for(int i=0;i<c;i++)
s2[i]=st.nextToken();
//打印数组的各元素
for(int j=0;j<s2.length;j++)
System.out.println("array["+j+"] :"+s2[j]);
}
}
}
String str = "This is a test string.I am student";
StringTokenizer token = new StringTokenizer(str," .");
while(token.hasMoreTokens()){
v.add(token.nextElement());
}
String[] res = new String[v.size()];
v.toArray(res);
注意这行 StringTokenizer token = new StringTokenizer(str," .");
的第二个参数,可以增加到完全适合你的需要.
import java.util.*;public class test {
public static void main(String args[]) {
try {
java.util.Vector v = new Vector();//store the data
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
while (true) {
System.out.print("Input: ");
String line = in.readLine();
if(line.toLowerCase().equals("quit")) {
System.out.println("Now Quit!");
break;
}
StringTokenizer div = new StringTokenizer(line," ",false);
while(div.hasMoreTokens()) {
v.add(div.nextToken());
}
for(int i = 0;i < v.size();i++) {
System.out.println(v.elementAt(i));
}
}
} catch (Exception e) {
System.out.println(" caught a " + e.getClass() +
"\n with message: " + e.getMessage());
}
}
}
my name is aizhu1005
输完之后按回车,然后程序自动显示结果
可以无限输入