
{"id":2164,"date":"2020-08-24T07:58:19","date_gmt":"2020-08-23T23:58:19","guid":{"rendered":"http:\/\/127.0.0.2\/?p=2164"},"modified":"2020-08-24T11:27:30","modified_gmt":"2020-08-24T03:27:30","slug":"2020java%e6%95%99%e7%a8%8b%ef%bc%9a%e9%9b%86%e5%90%88%e6%a1%86%e6%9e%b6","status":"publish","type":"post","link":"https:\/\/www.9713job.com\/?p=2164","title":{"rendered":"2020java\u6559\u7a0b\uff1a\u96c6\u5408\u6846\u67b6\u4e4bList\u96c6\u5408"},"content":{"rendered":"<h3>\u96c6\u5408\u6846\u67b6\u4e4bList\u96c6\u5408<\/h3>\n<p>\u4ec0\u4e48\u662f\u96c6\u5408<br \/>\n\u6982\u5ff5\uff1a\u5bf9\u8c61\u7684\u5bb9\u5668\uff0c\u5b58\u50a8\u5bf9\u8c61\u7684\u5bf9\u8c61\uff0c\u53ef\u4ee3\u66ff\u6570\u7ec4<br \/>\n\u7279\u70b9\uff1a\u5bb9\u5668\u7684\u5de5\u5177\u7c7b\uff0c\u5b9a\u4e49\u4e86\u5bf9\u591a\u4e2a\u5bf9\u8c61\u8fdb\u884c\u64cd\u4f5c\u7684\u5e38\u7528\u65b9\u6cd5<br \/>\n\u4f4d\u7f6e\uff1ajava.util.*;<\/p>\n<p><strong>collection\u4f53\u7cfb\u96c6\u5408<\/strong><br \/>\ninterface collection\u8be5\u4f53\u7cfb\u7ed3\u6784\u7684\u6839\u63a5\u53e3\uff0c\u4ee3\u8868\u4e00\u7ec4\u5bf9\u8c61\uff0c\u79f0\u4e3a\u96c6\u5408<br \/>\n|-interface List\uff1aList\u63a5\u53e3\u7684\u7279\u70b9\uff1a\u6709\u5e8f\u6709\u4e0b\u6807\uff0c\u5143\u7d20\u53ef\u91cd\u590d<br \/>\n|&#8211;class ArrayList\u3001Class LinkedList\u3001Class Vector<br \/>\n|-interface Set\uff1aSet\u63a5\u53e3\u7684\u7279\u70b9\uff1a\u65e0\u5e8f\u65e0\u4e0b\u6807\u5143\u7d20\u4e0d\u53ef\u91cd\u590d<br \/>\n|&#8211;Class HashSet\u3001Class SortedSet\u3001Class TreeSet<!--more--><\/p>\n<p><strong>Collection\u7236\u63a5\u53e3<\/strong><br \/>\n\u7279\u70b9\uff1a\u4ee3\u8868\u4e00\u7ec4\u4efb\u610f\u7c7b\u578b\u7684\u5bf9\u8c61\uff0c\u65e0\u5e8f\u65e0\u4e0b\u6807<br \/>\n\u65b9\u6cd5\uff1a<br \/>\nboolean add(Obect obj)\/\/\u6dfb\u52a0\u4e00\u4e2a\u5bf9\u8c61<br \/>\nboolean addAll(Collection c)\/\/\u5c06\u4e00\u4e2a\u96c6\u5408\u4e2d\u7684\u6240\u6709\u5bf9\u8c61\u6dfb\u52a0\u5230\u6b64\u96c6\u5408\u4e2d<br \/>\nvoid clear();\/\/\u6e05\u7a7a\u6b64\u96c6\u5408\u4e2d\u7684\u6240\u6709\u5bf9\u8c61<br \/>\nboolean contains(Object obj);\/\/\u68c0\u67e5\u6b64\u96c6\u5408\u662f\u5426\u5305\u542bobj\u5bf9\u8c61<br \/>\nboolean equals(Object obj);\/\/\u6bd4\u8f83\u6b64\u96c6\u5408\u662f\u5426\u4e0e\u6307\u5b9a\u5bf9\u8c61\u76f8\u7b49<br \/>\nboolean isEmpty();\/\/\u5224\u65ad\u6b64\u96c6\u5408\u662f\u5426\u4e3a\u7a7a<br \/>\nboolean remove(Object obj);\/\/\u5728\u6b64\u96c6\u5408\u79fb\u9664obj\u5bf9\u8c61<br \/>\nint size();\/\/\u8fd4\u56de\u6b64\u96c6\u5408\u4e2d\u7684\u5143\u7d20\u4e2a\u6570<br \/>\nObject[] toArray();\/\/\u5c06\u6b64\u96c6\u5408\u8f6c\u6362\u6210\u6570\u7ec4<\/p>\n<p><strong>List\u96c6\u5408<\/strong><\/p>\n<p>List\u5b50\u63a5\u53e3<br \/>\n\u7279\u70b9\uff1a\u6709\u5e8f\u6709\u4e0b\u6807\u5143\u7d20\u53ef\u91cd\u590d<br \/>\n\u65b9\u6cd5\uff1a<br \/>\nvoid add(int index,Object o);\/\/\u5728index\u4f4d\u7f6e\u63d2\u5165\u5bf9\u8c610<br \/>\nboolean addAll(int index,Collection c);\/\/\u5c06\u4e00\u4e2a\u96c6\u5408\u4e2d\u7684\u5143\u7d20\u6dfb\u52a0\u5230\u6b64\u96c6\u5408\u4e2d\u7684index\u4f4d\u7f6e<br \/>\nObject get(int index);\/\/\u8fd4\u56de\u96c6\u5408\u4e2d\u6307\u5b9a\u4f4d\u7f6e\u7684\u5143\u7d20<br \/>\nList subList(int fromIndex,int toIndex);\/\/\u8fd4\u56defromIndex\u548ctoIndex\u4e4b\u95f4\u7684\u96c6\u5408\u5143\u7d20<\/p>\n<pre>public static void main(String[] args) {\r\n    ArrayList list=new ArrayList();\r\n    list.add(8);\r\n    list.add(158.8);\r\n    list.add(\"hello\");\r\n    list.add(true);\r\n    list.add('A');\r\n    for(int i=0;i&lt;list.size();i++){\r\n        System.out.println(list.get(i));\r\n    }\r\n}<\/pre>\n<p><strong>List\u5b9e\u73b0\u7c7b<br \/>\n<\/strong><\/p>\n<p>ArrayList:<br \/>\n\u6570\u7ec4\u7ed3\u6784\u5b9e\u73b0\uff0c\u67e5\u8be2\u5feb\uff0c\u589e\u5220\u6162<br \/>\nJDK1.2\u7248\u672c\uff0c\u8fd0\u884c\u6548\u7387\u5feb\uff0c\u7ebf\u7a0b\u4e0d\u5b89\u5168<\/p>\n<p>Vector\uff1a<br \/>\n\u6570\u7ec4\u7ed3\u6784\u5b9e\u73b0\uff0c\u67e5\u8be2\u5feb\uff0c\u589e\u5220\u6162<br \/>\nJDK1.0\u7248\u672c\uff0c\u8fd0\u884c\u6548\u7387\u6162\uff0c\u7ebf\u7a0b\u5b89\u5168<\/p>\n<p>LinkedList:<br \/>\n\u94fe\u8868\u7ed3\u6784\u5b9e\u73b0\uff0c\u589e\u5220\u5feb\uff0c\u67e5\u8be2\u6162<\/p>\n<p><strong>\u4e0d\u540c\u7ed3\u6784\u5b9e\u73b0\u65b9\u5f0f<\/strong><\/p>\n<p>ArrayList:\u5fc5\u987b\u5f00\u8f9f\u8fde\u7eed\u7a7a\u95f4\uff0c\u67e5\u8be2\u5feb\uff0c\u589e\u5220\u6162<br \/>\nLinkedList:\u65e0\u5e8f\u5f00\u8f9f\u8fde\u7eed\u7a7a\u95f4\uff0c\u67e5\u8be2\u6162\uff0c\u589e\u5220\u5feb<\/p>\n<p><strong>\u6cdb\u578b\u96c6\u5408<\/strong><\/p>\n<p>\u6982\u5ff5\uff1a\u53c2\u6570\u5316\u7c7b\u578b\u3001\u7c7b\u578b\u5b89\u5168\u7684\u96c6\u5408\uff0c\u5f3a\u5236\u96c6\u5408\u5143\u7d20\u7684\u7c7b\u578b\u5fc5\u987b\u4e00\u81f4<br \/>\n\u7279\u70b9\uff1a<br \/>\n\u7f16\u8bd1\u65f6\u5373\u53ef\u68c0\u67e5\uff0c\u800c\u975e\u8fd0\u884c\u65f6\u629b\u5f02\u5e38<br \/>\n\u8bbf\u95ee\u65f6\uff0c\u4e0d\u5fc5\u7c7b\u578b\u8f6c\u6362(\u62c6\u7bb1)<\/p>\n<pre>public static void main(String[] args) {\r\n    List&lt;Integer&gt; list=new ArrayList&lt;Integer&gt;();\r\n    list.add(8);\r\n    list.add(12);\r\n    list.add(99);\r\n    for(int i=0;i&lt;list.size();i++){\r\n        System.out.println(list.get(i));\r\n    }\r\n}<\/pre>\n<p><strong>\u5b9e\u4f8b\u6cdb\u578b\u548c\u9759\u6001\u6cdb\u578b<\/strong><\/p>\n<pre>import java.util.*;\r\n\r\npublic class demos{\r\n    public static void main(String[] args) {\r\n        \/\/\u5b9e\u4f8b\u6cdb\u578b\r\n        MyClass&lt;Integer&gt; mc1=new MyClass&lt;Integer&gt;();\r\n        mc1.m1(22);\r\n        MyClass&lt;Double&gt; mc2=new MyClass&lt;Double&gt;();\r\n        mc2.m1(88.8);\r\n        MyInterface&lt;String&gt; mi=new MyImpClass();\r\n        mi.m2(\"hello\");\r\n        \/\/\u9759\u6001\u6cdb\u578b\r\n        MyStaticClass.method(\"hello\"); \/\/ERROR \u4e0d\u662f\u6570\u5b57\u7c7b\u578b\r\n        MyStaticClass.method(55);\r\n        MyStaticClass.method(89.9);\r\n        MyStaticClass.eat(new Dog());\r\n        MyStaticClass.eat(new Cat());\/\/ERROR \u732b\u6ca1\u6709\u5b9e\u73b0Comparable\u63a5\u53e3\r\n    }\r\n}\r\nclass MyStaticClass{\r\n    \/\/\u6cdb\u578b\u53ea\u652f\u6301\u6570\u7ec4\u7c7b\u578b\r\n    public static&lt;T extends Number&gt; void method(T t){}\r\n    \/\/\u6cdb\u578b\u53ea\u652f\u6301Animal\u5bf9\u8c61\u4ee5\u53ca\u5b9e\u73b0Comparable\u63a5\u53e3\r\n    public static&lt;T extends Animal&amp;Comparable&gt; void eat(T t){}\r\n}\r\nabstract class Animal{}\r\nclass Dog extends Animal implements Comparable{\r\n    @Override\r\n    public int compareTo(Object o) {\r\n        return 0;\r\n    }\r\n}\r\nclass Cat extends Animal{}\r\nclass MyClass&lt;T&gt;{public void m1(T t){}}\r\ninterface MyInterface&lt;T&gt;{\r\n    void m2(T t);\r\n}\r\nclass MyImpClass implements MyInterface&lt;String&gt;{\r\n    @Override\r\n    public void m2(String s) {}\r\n}<\/pre>\n<p><strong>Collections\u5de5\u5177\u7c7b<\/strong><\/p>\n<p>\u6982\u5ff5\uff1a\u96c6\u5408\u5de5\u5177\u7c7b\uff0c\u5b9a\u4e49\u4e86\u5b58\u53d6\u4ee5\u5916\u7684\u96c6\u5408\u5e38\u7528\u65b9\u6cd5<br \/>\n\u65b9\u6cd5\uff1a<br \/>\npublic static void reverse(List&lt;?&gt; list);\/\/\u53cd\u8f6c\u96c6\u5408\u4e2d\u5143\u7d20\u7684\u987a\u5e8f<br \/>\npublic static void shuffle(List&lt;?&gt; list);\/\/\u968f\u673a\u91cd\u7f6e\u96c6\u5408\u5143\u7d20\u7684\u987a\u5e8f<br \/>\npublic static void sort(List&lt;T&gt; list);\/\/\u5347\u5e8f\u6392\u5e8f(\u5fc5\u987b\u5b9e\u73b0Comparable\u63a5\u53e3)<\/p>\n<pre>LinkedList&lt;Integer&gt; list=new LinkedList&lt;Integer&gt;();\r\nlist.add(1);\r\nlist.add(3);\r\nlist.add(5);\r\nlist.add(7);\r\nlist.add(9);\r\nCollections.shuffle(list);\r\nCollections.reverse(list);\r\nCollections.sort(list);\r\nfor(int i=0;i&lt;list.size();i++){\r\n    System.out.println(list.get(i));\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u96c6\u5408\u6846\u67b6\u4e4bList\u96c6\u5408 \u4ec0\u4e48\u662f\u96c6\u5408 \u6982\u5ff5\uff1a\u5bf9\u8c61\u7684\u5bb9\u5668\uff0c\u5b58\u50a8\u5bf9\u8c61\u7684\u5bf9\u8c61\uff0c\u53ef\u4ee3\u66ff\u6570\u7ec4 \u7279\u70b9\uff1a\u5bb9\u5668\u7684\u5de5\u5177\u7c7b\uff0c\u5b9a\u4e49\u4e86\u5bf9 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-2164","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2164","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2164"}],"version-history":[{"count":4,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2164\/revisions"}],"predecessor-version":[{"id":2168,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2164\/revisions\/2168"}],"wp:attachment":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2164"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2164"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2164"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}