Android比较字符串有两种方法,但仍无效

时间:2015-03-17 21:00:23

标签: android

你能帮助我,为什么我的代码不起作用?

输出:

03-17 16:54:25.488:D / wew(3821):msg:test

03-17 16:54:25.488:I / System.out(3821):#1:false

03-17 16:54:25.488:I / System.out(3821):#2:false

这是我的代码:

        charsRead = in.read(buffer);
                        if (charsRead != 1) {
                            String message = new String(buffer).substring(
                                    0, charsRead).toString();
                            Log.d("wew", "msg :" + message);

                            String w1 = "test";
                            String w2 = message;

                            if(w1 == w2){
                                System.out.println("#1: true");
                                } else {
                                System.out.println("#1: false");
                                }

                                if(w1.equals(w2)){
                                System.out.println("#2: true");
                                } else {
                                System.out.println("#2: false");
                                }

                        }

0 个答案:

没有答案