作者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
1F:推 LPH66:不妨用 charAt 一个字一个字印出来看看是不是三个 97 ('a') 01/04 20:59
2F:→ adrianshum:天知道你的 temp 是什麽... 01/04 21:15
3F:→ kenlan:String s="aaa"; byte[] temp = s.getBytes(); 01/04 21:37
4F:→ kenlan:经测式,是三个97没错,但是问题还在 01/04 21:49
5F:→ sbrhsieh:怎麽会是这样测?! 01/04 23:42
6F:推 LPH66:不是要你测"aaa" 是要你测 msg... 01/06 03:04