目錄java
int i1=1; int i2=2; System.out.println(i1==i2);//結果爲true
Integer i1=Integer.valueOf(1); Integer i2=Integer.valueOf(1); System.out.println(i1==i2);//結果爲true
Integer i1=Integer.new(1); Integer i2=Integer.new(1); System.out.println(i1==i2);//結果爲false
Integer i1 =100; Integer i2 =100; if (i1 == i2){ System.out.println("i1 == i2"); } else { System.out.println("i1 != i2"); } //輸出i1==i2;
Integer i1 =200; Integer i2 =200; if (i1 == i2){ System.out.println("i1 == i2"); } else { System.out.println("i1 != i2"); } //輸出i1!=i2;
部分運行結果截圖:git
java -Djava.lang.Integer.IntegerCache.high=300;
//將範圍改成-128-300String s1="hello" String s2="hello" System.out.println(s1 == s2);//輸出結果爲true
String s1="hello"; String s2=s1; System.out.println(s1 == s2);//輸出結果爲true
String s1=new String("hello"); String s2=s1; s1=s1+"world"; System.out.printlns(s1==s2);//輸出結果爲false
StringBuilder s1=new StringBuilder("hello"); StringBuilder s2=s1; s1=s1,append("hello"); System.out.printlns(s1==s2);//輸出結果爲true
StringBuffer s1=new StringBuffer("hello"); StringBufferr s2=s1; s1=s1,append("hello"); System.out.printlns(s1==s2);//輸出結果爲true
部分運行結果截圖:數組
import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.lang.Integer; import java.util.Vector; public class TestList { public static List list = CreatList.creatList(); public static void main(String[] args) { if (args[0].equals("0")) { ArrayListTest(); } if (args[0].equals("1")) { VectorTest(); } if (args[0].equals("2")) { LinkListTest(); } } public static void ArrayListTest() { ArrayList arrayList = new ArrayList(list); int index3 = arrayList.indexOf(Integer.valueOf(35)); System.out.println(index3); } public static void VectorTest() { Vector vector = new Vector(list); int index3 = vector.indexOf(Integer.valueOf(35)); System.out.println(index3); } public static void LinkListTest() { LinkedList linkedList = new LinkedList(list); int index3 = linkedList.indexOf(35); System.out.println(index3); } }
運行結果截圖:微信
import java.util.Iterator; import java.util.Map; public class HashMap { public static void main(String[] args) { Map<String, String> map1= new java.util.HashMap<String, String>(); map1.put("20175313","張黎仙"); map1.put("20175314","薛勐"); map1.put("20175312","陶光遠"); map1.put("20175316","盛茂淞"); map1.put("20175311","胡濟棟"); map1.put("20175315","陳煜揚"); long start1=System.currentTimeMillis(); Iterator<Map.Entry<String, String>> it1 = map1.entrySet().iterator(); while (it1.hasNext()) { Map.Entry<String, String> e = it1.next(); System.out.println("Key: " + e.getKey() + "; Value: " + e.getValue()); } } }
import java.util.HashMap; import java.util.Hashtable; import java.util.Map; import java.util.TreeMap; import java.util.Iterator; public class HashTable { public static void main(String[] args) { Map<String, String> map= new Hashtable<String, String>(); map.put("20175313","張黎仙"); map.put("20175314","薛勐"); map.put("20175312","陶光遠"); map.put("20175316","盛茂淞"); map.put("20175311","胡濟棟"); map.put("20175315","陳煜揚"); long start=System.currentTimeMillis(); Iterator<Map.Entry<String, String>> it = map.entrySet().iterator(); while (it.hasNext()) { Map.Entry<String, String> e = it.next(); System.out.println("Key: " + e.getKey() + "; Value: " + e.getValue()); } } }
import java.util.Iterator; import java.util.Map; public class TreeMap { public static void main(String[] args) { Map<String, String> map2= new java.util.TreeMap<String, String>(); map2.put("20175313","張黎仙"); map2.put("20175314","薛勐"); map2.put("20175312","陶光遠"); map2.put("20175316","盛茂淞"); map2.put("20175311","胡濟棟"); map2.put("20175315","陳煜揚"); long start2=System.currentTimeMillis(); Iterator<Map.Entry<String, String>> it2 = map2.entrySet().iterator(); while (it2.hasNext()) { Map.Entry<String, String> e = it2.next(); System.out.println("Key: " + e.getKey() + "; Value: " + e.getValue()); } } }
運行結果截圖:多線程