1 Importjava.util.ArrayList;2 3 Public classMain {4 5 Public Static voidMain (string[] args) {6StringBuffer buffer =NewStringBuffer ("Hello World."));7 8StringBuffer Buffer_other =buffer;9 TenBuffer.append ("Me too."); One A if(Buffer = =buffer_other) { -System.out.println ("OK.")); - } the - - //buffer.append (null); Error -String str =NULL; + System.out.println (Buffer.append (str)); - //output: Hello world.me Too.null When the string is null, StringBuffer's append () converts null to a string null plus at the end + Aarraylist<string> list =NewArraylist<>(); at List.add (str); -System.out.println (list.get (0));//output is null -List.add (NULL); -System.out.println (List.get (1));//output is null - - /********************************/ inString string =NULL; -String string2 =NULL; toArraylist<string> ArrayList =NULL; + if(String = =string2) { -System.out.println ("Y");//Output y the } * if(String = =NULL) { $System.out.println ("Y");//Output yPanax Notoginseng } - if(NULL==NULL) { theSystem.out.println ("Y");//Output y + } A //String = = ArrayList is a syntax error the + //if (string.equals (string2)) {//NullPointerException - //System.out.println ("Y"); $ //} $ - } -}
Some Java knowledge points