首页 > 代码库 > 一些Java知识点

一些Java知识点

 1 import java.util.ArrayList; 2  3 public class Main { 4      5     public static void main(String[] args) { 6         StringBuffer buffer = new StringBuffer("Hello World."); 7          8         StringBuffer buffer_other = buffer; 9         10         buffer.append("Me too.");11         12         if (buffer == buffer_other) {13             System.out.println("OK.");14         }15         16         17         //buffer.append(null); 报错18         String str = null;19         System.out.println(buffer.append(str));20         //输出:Hello World.Me too.null 当字符串为null时,StringBuffer的append()会把null 转化为字符串null加在结尾21         22         ArrayList<String> list = new ArrayList<>();23         list.add(str);24         System.out.println(list.get(0));//输出为null25         list.add(null);26         System.out.println(list.get(1));//输出为null27         28         /********************************/29         String string = null;30         String string2 = null;31         ArrayList<String> arrayList = null;32         if (string == string2) {33             System.out.println("Y");//输出Y34         }35         if (string == null) {36             System.out.println("Y");//输出Y37         }38         if (null == null) {39             System.out.println("Y");//输出Y40         }41         //string == arrayList  是语法错误42         43         //if (string.equals(string2)) {//NullPointerException44         //    System.out.println("Y");45         //}46         47     }48 }

 

一些Java知识点