📄 readstringswitharraylist.java
字号:
/**读入不限长的字符串并将其输出的程序,运用了数组列表。*/
import java.io.*;
import java.util.*;
public class ReadStringsWithArrayList {
public static void main(String args[]){
ArrayList array=getStrings();
for(int i=0;i<array.size();i++)
System.out.println(array.get(i));
}//Read an unlimited number of String ;return a String[]
//The minimal I/O details used here are not important for
//this example and are discussed in Section 2.6
public static ArrayList getStrings(){
BufferedReader in =new BufferedReader (new InputStreamReader(System.in));
ArrayList array=new ArrayList();
String oneLine;
System.out.println("Enter strings ,one per line;");
System.out.println("Terninate with empty line:");
try{oneLine=in.readLine();
while((oneLine)!=null&!oneLine.equals(" "))
array.add(oneLine);
}catch(IOException e){
System.out.println("Eaarly abort of read.");
}return array;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -