作者kenlan (kenlan )
看板java
標題[問題] 有關byte的問題
時間Tue Jan 4 19:25:36 2011
大家好,我遇到了一個byte的問題
byte Input[] = new byte[temp.length];
for (int i = 0; i < temp.length; i++) {
Input[i] = temp[i];
}
String msg = new String(Input);
System.out.println(msg);
此為印出 aaa
if(msg.equals("aaa"))
System.out.println("hello");
印不出hello
代表雖然msg是aaa,可是使用equals失敗了
要怎樣才能使用equals呢??或是有其它類似equals的方法
我用 msg == "aaa" 也是失敗了
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.40.155.202
推 LPH66:不妨用 charAt 一個字一個字印出來看看是不是三個 97 ('a') 01/04 20:59
→ adrianshum:天知道你的 temp 是什麼... 01/04 21:15
→ kenlan:String s="aaa"; byte[] temp = s.getBytes(); 01/04 21:37
→ kenlan:經測式,是三個97沒錯,但是問題還在 01/04 21:49
→ sbrhsieh:怎麼會是這樣測?! 01/04 23:42
推 LPH66:不是要你測"aaa" 是要你測 msg... 01/06 03:04