##今天的筆記 **Bufferreader:** 使用BufferedReader物件的readLine()方法必須處理java.io.IOException異常(Exception)。 BufferReader讀取的資料都以字串的形式儲存,如果需要其他形式的資料,需要進行強制轉換。 ``` import java.io.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader br1=new BufferedReader(new InputStreamReader(System.in));//建立BufferedReader物件,從鍵盤讀入 BufferedReader br2= new BufferedReader(new FileReader("test.txt"));//建立BufferedReader物件,從文字檔案讀入 String str = br.readLine(); //讀取一行字串 int a = Integer.parseInt(str); //將字元轉化為整型 System.out.println(a); String[] temp=br1.readLine().split(" ");//讀取一行資料並用空格分隔,存入字串陣列 } } ``` **##ArrayList:** 提供新增ˋ修改ˋ刪除等.... ``` package beginnersbook.com; import java.util.ArrayList; public class GetMethodExample { public static void main(String[] args) { ArrayList<String> al = new ArrayList<String>(); al.add("pen"); al.add("pencil"); al.add("ink"); al.add("notebook"); al.add("book"); al.add("books"); al.add("paper"); al.add("white board"); System.out.println("First element of the ArrayList: "+al.get(0)); System.out.println("Third element of the ArrayList: "+al.get(2)); System.out.println("Sixth element of the ArrayList: "+al.get(5)); System.out.println("Fourth element of the ArrayList: "+al.get(3)); } } ``` **length**: Arrays (int[], double[], String[]) — 取得Array的長度 **length()**: String related Object (String, StringBuilder, etc) — 取得字串的長度 **size():** Collection Object (ArrayList, Set, etc) — 取得集合物件相關大小 ``` import java.util.*; public class HelloWorld{ public static void main(String []args){ String[] arr = {"a", "b", "c"}; String s = "123456"; Set<String> set = new HashSet(); set.add("example"); System.out.println(arr.length); //3 System.out.println(s.length()); //6 System.out.println(set.size()); //1 } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up