看板 java 關於我們 聯絡資訊
※ 引述《yangmie (楊咩)》之銘言: : char[] temp=people.Name.toCharArray(); : 若我將一個字串轉成字元陣列後 : 想要把其中的一個字元拿出來判斷 : 可以寫成 : if(temp[0]=='\n')....... : 這樣子嗎? : 我如果這樣寫會跑出 : ArrayIndexOutOfBoundsException : 0 : 但是若要一個一個print(temp[0])卻可以 : 是為什麼呢? 這個明顯只是你第一句的地方, 原本的 string 是 empty string. 轉成 char[] 當然是 0 長度的 array. 取 temp[0] 當然就 array out of bounds 你一個一個 print 我猜你是 for (int i = 0; i < temp.length; ++i) { System.out.print(temp[i]]); } 這種吧. 這樣寫你根本就沒有取用過 temp[0] alien -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 202.155.236.82