{"id":1207,"date":"2022-10-26T23:09:40","date_gmt":"2022-10-26T15:09:40","guid":{"rendered":"https:\/\/qaqaq.top\/?p=1207"},"modified":"2022-11-27T12:39:48","modified_gmt":"2022-11-27T04:39:48","slug":"arraylist-%e6%ba%90%e7%a0%81%e8%a7%a3%e6%9e%90jdk11","status":"publish","type":"post","link":"https:\/\/qaqaq.top\/?p=1207","title":{"rendered":"ARRAYLIST \u6e90\u7801\u89e3\u6790(JDK11)"},"content":{"rendered":"\n<p>\u4e4b\u524d\u6709\u5199\u8fc7\u5173\u4e8e&nbsp;<code>ArrayList<\/code>&nbsp;\u7684\u6e90\u7801\u89e3\u6790\uff0c\u5f53\u65f6\u662f\u57fa\u4e8e JDK8 \u7684\uff0c\u73b0\u5728 JDK11 \u53d8\u6210\u4e86&nbsp;<code>LTS<\/code>&nbsp;\u7248\u672c\uff0c\u91cd\u65b0\u770b\u4e00\u904d\u6e90\u7801\u5e76\u505a\u76f8\u5173\u8bb0\u5f55\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a target=\"_blank\" rel=\"noreferrer noopener\"><\/a>\u6982\u89c8<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>ArrayList \u5e95\u5c42\u57fa\u4e8e\u52a8\u6001\u6570\u7ec4\uff0c\u5e76\u4e14\u5bb9\u91cf\u53ef\u53d8<\/li><li>ArrayList \u662f\u7ebf\u7a0b\u4e0d\u5b89\u5168\u7684\uff0c\u6548\u7387\u8f83\u9ad8<\/li><li>ArrayList \u4e2d&nbsp;<code>size()<\/code>,&nbsp;<code>isEmpty()<\/code>,&nbsp;<code>get()<\/code>,&nbsp;<code>set()<\/code>,&nbsp;<code>iterator()<\/code>, and&nbsp;<code>listIterator()<\/code>\u64cd\u4f5c\u8017\u65f6\u4e3a\u5e38\u6570\u65f6\u95f4<\/li><li>ArrayList \u4e2d&nbsp;<code>add()<\/code>&nbsp;\u8017\u65f6\u4e3a&nbsp;<code>amortized constant time<\/code>, \u4e5f\u5c31\u662f\u6240\uff0c\u589e\u52a0 n \u4e2a\u5143\u7d20\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a&nbsp;<code>O(n)<\/code><\/li><li>\u5176\u4ed6\u7684\u64cd\u4f5c\u8fd0\u884c\u65f6\u95f4\u4e3a<code>linear time<\/code><\/li><li><code>constant facto<\/code>r \u7684\u503c\u6bd4<code>LinkedList<\/code>&nbsp;\u7684\u5c0f<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>amortized constant time\n\nThe details of the growth policy are not specified beyond the fact that adding an element has constant amortized time cost.\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><a target=\"_blank\" rel=\"noreferrer noopener\"><\/a>\u7c7b\u540d<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>public class ArrayList&lt;E&gt; extends AbstractList&lt;E&gt;\n        implements List&lt;E&gt;, RandomAccess, Cloneable, java.io.Serializable\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>public abstract class AbstractList&lt;E&gt; extends AbstractCollection&lt;E&gt; implements List&lt;E&gt;\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>public abstract class AbstractCollection&lt;E&gt; implements Collection&lt;E&gt;\n<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>This class provides a skeletal implementation of the&nbsp;<a href=\"https:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/util\/List.html\" rel=\"noreferrer noopener\" target=\"_blank\"><code>List<\/code><\/a>&nbsp;interface to minimize the effort required to implement this interface backed by a \u201crandom access\u201d data store (such as an array). For sequential access data (such as a linked list),&nbsp;<a href=\"https:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/util\/AbstractSequentialList.html\" rel=\"noreferrer noopener\" target=\"_blank\"><code>AbstractSequentialList<\/code><\/a>&nbsp;should be used in preference to this class.<\/p><p>To implement an unmodifiable list, the programmer needs only to extend this class and provide implementations for the&nbsp;<a href=\"https:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/util\/AbstractList.html#get(int)\" rel=\"noreferrer noopener\" target=\"_blank\"><code>get(int)<\/code><\/a>&nbsp;and&nbsp;<a href=\"https:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/util\/List.html#size()\" rel=\"noreferrer noopener\" target=\"_blank\"><code>size()<\/code><\/a>&nbsp;methods.<\/p><p>To implement a modifiable list, the programmer must additionally override the [<code>set(int, E)<\/code>](https:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/util\/AbstractList.html#set(int, E)) method (which otherwise throws an&nbsp;<code>UnsupportedOperationException<\/code>). If the list is variable-size the programmer must additionally override the [<code>add(int, E)<\/code>](https:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/util\/AbstractList.html#add(int, E)) and&nbsp;<a href=\"https:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/util\/AbstractList.html#remove(int)\" rel=\"noreferrer noopener\" target=\"_blank\"><code>remove(int)<\/code><\/a>&nbsp;methods.<\/p><p>The programmer should generally provide a void (no argument) and collection constructor, as per the recommendation in the&nbsp;<a href=\"https:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/util\/Collection.html\" rel=\"noreferrer noopener\" target=\"_blank\"><code>Collection<\/code><\/a>&nbsp;interface specification.<\/p><p>Unlike the other abstract collection implementations, the programmer does&nbsp;<em>not<\/em>&nbsp;have to provide an iterator implementation; the iterator and list iterator are implemented by this class, on top of the \u201crandom access\u201d methods:&nbsp;<a href=\"https:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/util\/AbstractList.html#get(int)\" rel=\"noreferrer noopener\" target=\"_blank\"><code>get(int)<\/code><\/a>, [<code>set(int, E)<\/code>](https:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/util\/AbstractList.html#set(int, E)), [<code>add(int, E)<\/code>](https:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/util\/AbstractList.html#add(int, E)) and&nbsp;<a href=\"https:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/util\/AbstractList.html#remove(int)\" rel=\"noreferrer noopener\" target=\"_blank\"><code>remove(int)<\/code><\/a>.[4]<\/p><\/blockquote>\n\n\n\n<ul class=\"wp-block-list\"><li>\u7531\u4e0a\u8ff0\u5f15\u7528\u53ef\u77e5\uff0cJDK \u8bbe\u8ba1&nbsp;<code>AbstractList<\/code>\u7684\u76ee\u7684\u662f\u4e3a\u4e86\u63d0\u4f9b\u4e00\u4e2a\u5b9e\u73b0 List (\u5e95\u5c42\u4e3a\u6570\u7ec4\uff0c\u652f\u6301 random access)\u7684\u9aa8\u67b6\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u7ee7\u627f&nbsp;<code>AbstractList<\/code>&nbsp;\u5f00\u53d1\u81ea\u5df1\u7684&nbsp;<code>List<\/code>&nbsp;\u5b9e\u73b0\u7c7b\u3002<code>ArrayList<\/code>&nbsp;\u7ee7\u627f\u81ea&nbsp;<code>AbstractList<\/code>\uff0c\u8fd9\u6837\u505a\u7684\u597d\u5904\u662f\u53ef\u4ee5\u51cf\u5c11\u91cd\u590d\u4ee3\u7801\uff0c ArrayList \u53ea\u9700\u8981\u5173\u6ce8\u81ea\u5df1\u72ec\u6709\u7684\u65b9\u6cd5\u5373\u53ef\u3002<\/li><li><code>AbstractList<\/code>&nbsp;\u5b9e\u73b0\u4e86&nbsp;<code>List<\/code>&nbsp;\u63a5\u53e3\uff0c<code>ArrayList<\/code>&nbsp;\u53c8\u5b9e\u73b0\u4e86\u4e00\u904d&nbsp;<code>List<\/code>&nbsp;\u63a5\u53e3\uff0c\u662f\u4e3a\u4e86\u91cd\u5199\u4e00\u4e9b\u81ea\u5df1\u7279\u6709\u7684\u65b9\u6cd5\u3002<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>public interface RandomAccess {\n}\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>public interface Cloneable {\n}\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>public interface Serializable {\n}\n<\/code><\/pre>\n\n\n\n<p><code>RandomAccess<\/code>\uff0c&nbsp;<code>Cloneable<\/code>&nbsp;\uff0c<code>Serializable<\/code>&nbsp;\u4e09\u4e2a\u90fd\u662f\u6807\u8bb0\u63a5\u53e3\uff0c\u7528\u6765\u8868\u5f0f&nbsp;<code>ArrayList<\/code>&nbsp;\u652f\u6301 \u968f\u673a\u8bfb\u53d6\uff0c\u514b\u9686\u548c\u5e8f\u5217\u5316\uff0c\u53cd\u5e8f\u5217\u5316\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a target=\"_blank\" rel=\"noreferrer noopener\"><\/a>\u53c2\u6570<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>private static final long serialVersionUID = 8683452581122892189L;\n\n<em>\/\/ \u9ed8\u8ba4\u521d\u59cb\u5316 ArrayList capacity 10<\/em>\nprivate static final int DEFAULT_CAPACITY = 10;\n\n<em>\/\/ \u7ed9\u7a7a\u5b9e\u4f8b\u7684\u5171\u4eab\u7a7a\u6570\u7ec4<\/em>\nprivate static final Object&#91;] EMPTY_ELEMENTDATA = {};\n\n<em>\/\/ \u4e3a\u9ed8\u8ba4size\u7684\u7a7a\u5b9e\u4f8b\u63d0\u4f9b\u7684\u7a7a\u6570\u7ec4<\/em>\nprivate static final Object&#91;] DEFAULTCAPACITY_EMPTY_ELEMENTDATA = {};\n\n<em>\/**\n * The array buffer into which the elements of the ArrayList are stored.\n * The capacity of the ArrayList is the length of this array buffer. Any\n * empty ArrayList with elementData == DEFAULTCAPACITY_EMPTY_ELEMENTDATA\n * will be expanded to DEFAULT_CAPACITY when the first element is added.\n *\/<\/em>\ntransient Object&#91;] elementData; <em>\/\/ non-private to simplify nested class access<\/em>\n\n<em>\/\/ The size of the ArrayList (the number of elements it contains).<\/em>\nprivate int size;\n\n<em>\/**\n * The maximum size of array to allocate (unless necessary).\n * Some VMs reserve some header words in an array.\n * Attempts to allocate larger arrays may result in\n * OutOfMemoryError: Requested array size exceeds VM limit\n *\/<\/em>\nprivate static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;\n<\/code><\/pre>\n\n\n\n<p>ArrayList \u8bbe\u7f6e\u4e86\u9ed8\u8ba4\u7684\u6700\u5927&nbsp;<code>size<\/code>&nbsp;\u4e3a&nbsp;<code>Integer.MAX_VALUE - 8<\/code>\uff0c\u56e0\u4e3a\u5b58\u50a8\u4e86 Array \u7684\u5934\u90e8\u4fe1\u606f\uff0c\u6240\u4ee5\u8fd9\u91cc\u9700\u8981\u51cf\u53bb8\uff0c\u6211\u4eec\u53ef\u4ee5\u5728 IBM \u7684\u6280\u672f\u535a\u5ba2\u4e0a\u770b\u5230\u5173\u4e8e Array \u7684\u5934\u6587\u4ef6\u63cf\u8ff0<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a target=\"_blank\" rel=\"noreferrer noopener\"><\/a>ANATOMY OF A JAVA ARRAY OBJECT<\/h2>\n\n\n\n<p>The shape and structure of an array object, such as an array of&nbsp;<code>int<\/code>&nbsp;values, is similar to that of a standard Java object. The primary difference is that the array object has an additional piece of metadata that denotes the array\u2019s size. An array object\u2019s metadata, then, consists of:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Class<\/strong>&nbsp;: A pointer to the class information, which describes the object type. In the case of an array of&nbsp;<code>int<\/code>&nbsp;fields, this is a pointer to the&nbsp;<code>int[]<\/code>&nbsp;class.<\/li><li><strong>Flags<\/strong>&nbsp;: A collection of flags that describe the state of the object, including the hash code for the object if it has one, and the shape of the object (that is, whether or not the object is an array).<\/li><li><strong>Lock<\/strong>&nbsp;: The synchronization information for the object \u2014 that is, whether the object is currently synchronized.<\/li><li><strong>Size<\/strong>&nbsp;: The size of the array.<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/www.freesion.com\/images\/618\/4b19c96ad8659c4ca7cced707c7bbf72.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/www.freesion.com\/images\/618\/4b19c96ad8659c4ca7cced707c7bbf72.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"Array Object 32bit\"\/><\/div><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/www.freesion.com\/images\/54\/67f2365250b57f4cc7f0eb9378b722f6.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/www.freesion.com\/images\/54\/67f2365250b57f4cc7f0eb9378b722f6.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"Array Object 64bit\"\/><\/div><\/figure>\n\n\n\n<p>Source from: [5]<\/p>\n\n\n\n<p><code>elementData<\/code>&nbsp;\u4f7f\u7528&nbsp;<code>transient<\/code>\u8fdb\u884c\u4fee\u9970\u610f\u5473\u7740\u53ef\u4ee5\u4e0d\u7528\u88ab\u5e8f\u5217\u5316.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a target=\"_blank\" rel=\"noreferrer noopener\"><\/a>\u6784\u9020\u5668<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>public ArrayList() {\n  this.elementData = DEFAULTCAPACITY_EMPTY_ELEMENTDATA;\n}\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>public ArrayList(int initialCapacity) {\n  if (initialCapacity &gt; 0) {\n    this.elementData = new Object&#91;initialCapacity];\n  } else if (initialCapacity == 0) {\n    this.elementData = EMPTY_ELEMENTDATA;\n  } else {\n    throw new IllegalArgumentException(\"Illegal Capacity: \"+\n                                       initialCapacity);\n  }\n}\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><a target=\"_blank\" rel=\"noreferrer noopener\"><\/a>ADD\u65b9\u6cd5<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>public boolean add(E e) {\n  modCount++;\n  add(e, elementData, size);\n  return true;\n}\n\n<em>\/**\n * This helper method split out from add(E) to keep method\n * bytecode size under 35 (the -XX:MaxInlineSize default value),\n * which helps when add(E) is called in a C1-compiled loop.\n *\/<\/em>\nprivate void add(E e, Object&#91;] elementData, int s) {\n  if (s == elementData.length)\n    elementData = grow();\n  elementData&#91;s] = e;\n  size = s + 1;\n}\n\npublic void add(int index, E element) {\n    rangeCheckForAdd(index);\n    modCount++;\n    final int s;\n    Object&#91;] elementData;\n    if ((s = size) == (elementData = this.elementData).length)\n        elementData = grow();\n    System.arraycopy(elementData, index,\n                     elementData, index + 1,\n                     s - index);\n    elementData&#91;index] = element;\n    size = s + 1;\n}\n\nprivate Object&#91;] grow() {\n  return grow(size + 1);\n}\n\nprivate Object&#91;] grow(int minCapacity) {\n  return elementData = Arrays.copyOf(elementData,\n                                     newCapacity(minCapacity));\n}\n\n<em>\/**\n * Returns a capacity at least as large as the given minimum capacity.\n * Returns the current capacity increased by 50% if that suffices.\n * Will not return a capacity greater than MAX_ARRAY_SIZE unless\n * the given minimum capacity is greater than MAX_ARRAY_SIZE.\n *\/<\/em>\nprivate int newCapacity(int minCapacity) {\n  <em>\/\/ overflow-conscious code<\/em>\n  int oldCapacity = elementData.length;\n  int newCapacity = oldCapacity + (oldCapacity &gt;&gt; 1);\n  if (newCapacity - minCapacity &lt;= 0) {\n    if (elementData == DEFAULTCAPACITY_EMPTY_ELEMENTDATA)\n      return Math.max(DEFAULT_CAPACITY, minCapacity);\n    if (minCapacity &lt; 0) <em>\/\/ overflow<\/em>\n      throw new OutOfMemoryError();\n    return minCapacity;\n  }\n  return (newCapacity - MAX_ARRAY_SIZE &lt;= 0)\n    ? newCapacity\n    : hugeCapacity(minCapacity);\n}\n\nprivate static int hugeCapacity(int minCapacity) {\n  if (minCapacity &lt; 0) <em>\/\/ overflow<\/em>\n    throw new OutOfMemoryError();\n  return (minCapacity &gt; MAX_ARRAY_SIZE)\n    ? Integer.MAX_VALUE\n    : MAX_ARRAY_SIZE;\n}\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><a target=\"_blank\" rel=\"noreferrer noopener\"><\/a>\u6269\u5bb9<\/h3>\n\n\n\n<p>elementData\u7684\u6269\u5bb9\u673a\u5236\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u82e5\uff08\u5f53\u524d\u6570\u7ec4\u957f\u5ea6\u76841.5\u500d\uff09&lt;=\uff08\u5f53\u524d\u6570\u7ec4\u5143\u7d20\u4e2a\u6570+1\uff09<ul><li>\u82e5 ArrayList \u5bf9\u8c61\u662f\u7528\u65e0\u53c2\u6784\u9020\u5668\u521b\u5efa\u7684\uff0c\u7b2c\u4e00\u6b21\u8c03\u7528&nbsp;<code>add<\/code>&nbsp;\u65f6\u8ba1\u7b97\u51fa\u7684&nbsp;<code>newCapacity<\/code>&nbsp;\u4e3a&nbsp;<code>DEFAULT_CAPACITY = 10<\/code><\/li><li>\u82e5 size + 1 &lt; 0 (overflow)\uff0c\u629b\u51fa<code>OutOfMemoryError<\/code><\/li><li>\u5176\u4ed6\u60c5\u51b5\u8fd4\u56de size + 1<\/li><\/ul><\/li><li>\u82e5\uff08\u5f53\u524d\u6570\u7ec4\u957f\u5ea6\u76841.5\u500d\uff09&gt;\uff08\u5f53\u524d\u6570\u7ec4\u5143\u7d20\u4e2a\u6570+1\uff09<ul><li>\u82e5 newCapacity &lt;= MAX_ARRAY_SIZE\uff0c \u8fd4\u56de newCapacity\uff08\u5f53\u524d\u6570\u7ec4\u957f\u5ea6\u76841.5\u500d\uff09<\/li><\/ul><\/li><li>\u5426\u5219<code>return (minCapacity &gt; MAX_ARRAY_SIZE) ? Integer.MAX_VALUE : MAX_ARRAY_SIZE;<\/code><\/li><\/ul>\n\n\n\n<p>\u6269\u5bb9\u4f7f\u7528\u7684\u65b9\u6cd5\u4e3a\uff1a<code>Arrays.copyOf(T[] original, int newLength)<\/code>&nbsp;<code>System.arraycopy(Object src, int srcPos, Object dest, int destPos, int length)<\/code><\/p>\n\n\n\n<p><strong>\u6269\u5bb9\u7684\u65f6\u673a<\/strong>\uff1a\u5f53&nbsp;<code>size == elementData.length<\/code>\u65f6\uff0c\u4f1a\u8fdb\u884c\u6269\u5bb9\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public static &lt;T&gt; T&#91;] copyOf(T&#91;] original, int newLength) {\n  return (T&#91;]) copyOf(original, newLength, original.getClass());\n}\n\n@HotSpotIntrinsicCandidate\npublic static native void arraycopy(Object src,  int  srcPos,\n                                    Object dest, int destPos,\n                                    int length);\n\npublic static &lt;T,U&gt; T&#91;] copyOf(U&#91;] original, int newLength, Class&lt;? extends T&#91;]&gt; newType) {\n    @SuppressWarnings(\"unchecked\")\n    T&#91;] copy = ((Object)newType == (Object)Object&#91;].class)\n        ? (T&#91;]) new Object&#91;newLength]\n        : (T&#91;]) Array.newInstance(newType.getComponentType(), newLength);\n    System.arraycopy(original, 0, copy, 0,\n                     Math.min(original.length, newLength));\n    return copy;\n}\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><a target=\"_blank\" rel=\"noreferrer noopener\"><\/a>\u539f\u7406<\/h3>\n\n\n\n<p>\u6211\u4eec\u53ef\u4ee5\u770b\u5230\uff0c\u4e24\u4e2a add \u65b9\u6cd5\u90fd\u662f\u8c03\u7528&nbsp;<code>System.arraycopy<\/code>&nbsp;\u65b9\u6cd5\uff0c\u901a\u8fc7\u6570\u7ec4\u7684\u62f7\u8d1d\u6765\u5b8c\u6210 add \u64cd\u4f5c\uff0c\u56e0\u6b64 ArrayList \u589e\u52a0\u5143\u7d20\u901f\u5ea6\u8f83\u6162,\u5e76\u4e14\u6bcf\u6b21 add \u64cd\u4f5c\u90fd\u4f1a&nbsp;<code>modCount++<\/code><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><a target=\"_blank\" rel=\"noreferrer noopener\"><\/a>\u5bf9\u5e94 JDK8 \u6e90\u7801<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>public boolean add(E e) {\n  ensureCapacityInternal(size + 1);  <em>\/\/ Increments modCount!!<\/em>\n  elementData&#91;size++] = e;\n  return true;\n}\n\nprivate void ensureCapacityInternal(int minCapacity) {\n  ensureExplicitCapacity(calculateCapacity(elementData, minCapacity));\n}\n\nprivate void ensureExplicitCapacity(int minCapacity) {\n  modCount++;\n\n  <em>\/\/ overflow-conscious code<\/em>\n  if (minCapacity - elementData.length &gt; 0)\n    grow(minCapacity);\n}\n\nprivate void grow(int minCapacity) {\n  <em>\/\/ overflow-conscious code<\/em>\n  int oldCapacity = elementData.length;\n  int newCapacity = oldCapacity + (oldCapacity &gt;&gt; 1);\n  if (newCapacity - minCapacity &lt; 0)\n    newCapacity = minCapacity;\n  if (newCapacity - MAX_ARRAY_SIZE &gt; 0)\n    newCapacity = hugeCapacity(minCapacity);\n  <em>\/\/ minCapacity is usually close to size, so this is a win:<\/em>\n  elementData = Arrays.copyOf(elementData, newCapacity);\n}\n\nprivate static int hugeCapacity(int minCapacity) {\n  if (minCapacity &lt; 0) <em>\/\/ overflow<\/em>\n    throw new OutOfMemoryError();\n  return (minCapacity &gt; MAX_ARRAY_SIZE) ?\n    Integer.MAX_VALUE :\n  MAX_ARRAY_SIZE;\n}\n<\/code><\/pre>\n\n\n\n<p>\u6211\u4eec\u89c2\u5bdf\u6e90\u7801\u53ef\u77e5\uff0cJDK8 \u4e2d add \u65b9\u6cd5\u5927\u4f53\u4e0a\u548c JDK11 \u4e2d\u76f8\u540c\uff0c\u6269\u5bb9\u7684\u539f\u7406\u4e00\u6837\uff0c\u4e0d\u8fc7 JDK11 \u5c06&nbsp;<code>add(E element)<\/code>&nbsp;\u8fdb\u884c\u4e86\u62c6\u5206\uff0c\u8fd9\u6837\u53ef\u4ee5\u4f7f\u7528\u5185\u8054\u65b9\u6cd5\uff0c\u51cf\u5c11\u51fd\u6570\u8c03\u7528\u7684\u6210\u672c\uff0c\u505a\u4e86\u6539\u8fdb\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public boolean add(E e) {\n  modCount++;\n  add(e, elementData, size);\n  return true;\n}\n\n<em>\/**\n * This helper method split out from add(E) to keep method\n * bytecode size under 35 (the -XX:MaxInlineSize default value),\n * which helps when add(E) is called in a C1-compiled loop.\n *\/<\/em>\nprivate void add(E e, Object&#91;] elementData, int s) {\n  if (s == elementData.length)\n    elementData = grow();\n  elementData&#91;s] = e;\n  size = s + 1;\n}\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><a target=\"_blank\" rel=\"noreferrer noopener\"><\/a>REMOVE\u65b9\u6cd5<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>public E remove(int index) {\n   Objects.checkIndex(index, size);\n   final Object&#91;] es = elementData;\n\n   @SuppressWarnings(\"unchecked\") E oldValue = (E) es&#91;index];\n   fastRemove(es, index);\n\n   return oldValue;\n}\n\npublic boolean remove(Object o) {\n   final Object&#91;] es = elementData;\n   final int size = this.size;\n   int i = 0;\n   found: {\n       if (o == null) {\n           for (; i &lt; size; i++)\n               if (es&#91;i] == null)\n                   break found;\n       } else {\n           for (; i &lt; size; i++)\n               if (o.equals(es&#91;i]))\n                   break found;\n       }\n       return false;\n   }\n   fastRemove(es, i);\n   return true;\n}\n\nprivate void fastRemove(Object&#91;] es, int i) {\n   modCount++;\n   final int newSize;\n   if ((newSize = size - 1) &gt; i)\n       System.arraycopy(es, i + 1, es, i, newSize - i);\n   es&#91;size = newSize] = null;\n}\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><a target=\"_blank\" rel=\"noreferrer noopener\"><\/a>\u539f\u7406<\/h3>\n\n\n\n<p>\u89c2\u5bdf\u4e0a\u8ff0\u4ee3\u7801\u6211\u4eec\u53ef\u4ee5\u77e5\u9053 remove \u65b9\u6cd5\u4e3b\u8981\u901a\u8fc7\u5e95\u5c42\u8c03\u7528&nbsp;<code>System.arraycopy(es, i + 1, es, i, newSize - i);<\/code>&nbsp;\u901a\u8fc7\u6570\u7ec4\u7684\u62f7\u8d1d\u6765\u5b8c\u6210\uff0c\u8fd9\u4e5f\u662f\u4e3a\u4ec0\u4e48 ArrayList \u5220\u9664\u5143\u7d20\u8f83\u6162\uff0c\u5e76\u4e14\u6bcf\u6b21remove \u64cd\u4f5c\u90fd\u4f1a&nbsp;<code>modCount++<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a target=\"_blank\" rel=\"noreferrer noopener\"><\/a>SET\u65b9\u6cd5<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>public E set(int index, E element) {\n    Objects.checkIndex(index, size);\n    E oldValue = elementData(index);\n    elementData&#91;index] = element;\n    return oldValue;\n}\n\npublic static int checkIndex(int index, int length) {\n    return Preconditions.checkIndex(index, length, null);\n}\n\npublic static &lt;X extends RuntimeException&gt; int checkIndex(int index, int length,\n                   BiFunction&lt;String, List&lt;Integer&gt;, X&gt; oobef) {\n    if (index &lt; 0 || index &gt;= length)\n        throw outOfBoundsCheckIndex(oobef, index, length);\n    return index;\n}\n<\/code><\/pre>\n\n\n\n<p><strong>Set \u65b9\u6cd5\u5f88\u7b80\u5355\uff0c\u4f46\u662f\u8fd9\u91cc\u4f1a\u6709\u4e00\u4e2a bug \u9700\u8981\u6ce8\u610f\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>List&lt;Integer&gt; list = new ArrayList&lt;&gt;(11);\nSystem.out.println(list.size()); <em>\/\/ 0<\/em>\nlist.set(0, 1); <em>\/\/ throw java.lang.IndexOutOfBoundsException<\/em>\n<\/code><\/pre>\n\n\n\n<p>\u901a\u8fc7&nbsp;<code>new ArrayList&lt;&gt;(11);<\/code>&nbsp;<code>new ArrayList&lt;&gt;();<\/code>&nbsp;\u65b9\u6cd5\u521b\u5efa\u7684&nbsp;<strong>ArrayList \u5bf9\u8c61\u521d\u59cb\u7684 size \u90fd\u4e3a 0\uff0cset \u4e2d\u7684 index \u5fc5\u987b\u5c0f\u4e8e size<\/strong>\uff0c \u56e0\u6b64 \u8fdb\u884c set \u64cd\u4f5c\u662f\u5c31\u4f1a\u62a5&nbsp;<code>java.lang.IndexOutOfBoundsException<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a target=\"_blank\" rel=\"noreferrer noopener\"><\/a>GET\u65b9\u6cd5<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>public E get(int index) {\n    Objects.checkIndex(index, size);\n    return elementData(index);\n}\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><a target=\"_blank\" rel=\"noreferrer noopener\"><\/a>\u5e8f\u5217\u5316<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>transient Object&#91;] elementData; <em>\/\/ non-private to simplify nested class access<\/em>\n<\/code><\/pre>\n\n\n\n<p>ArrayList \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\uff0c\u5177\u6709\u52a8\u6001\u6269\u5bb9\u5c5e\u6027\uff0c\u56e0\u6b64 elementData \u53ef\u80fd\u4e0d\u4f1a\u88ab\u5b8c\u5168\u4f7f\u7528\uff0c\u8fd9\u79cd\u60c5\u51b5\u4e0b\u5c31\u6ca1\u5fc5\u8981\u5168\u90e8\u8fdb\u884c\u5e8f\u5217\u5316\uff0c\u6240\u4ee5\u4f1a\u7528&nbsp;<code>transient<\/code>&nbsp;\u8fdb\u884c\u4fee\u9970\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230<code>ArrayList<\/code>&nbsp;\u5b9e\u73b0\u4e86\u81ea\u5df1\u7684<code>writeObject<\/code>&nbsp;<code>readObject<\/code>&nbsp;\u65b9\u6cd5\uff0c<strong>\u6765\u63a7\u5236\u53ea\u5e8f\u5217\u5316\u6570\u7ec4\u4e2d \u6709\u5143\u7d20\u586b\u5145\u7684\u90a3\u90e8\u5206\u5185\u5bb9<\/strong>\uff0c\u5e76\u4e14&nbsp;<code>writeObject<\/code>&nbsp;\u8fc7\u7a0b\u4e2d\u4f1a\u68c0\u67e5\u662f\u5426\u6709\u7ed3\u6784\u6027\u4fee\u6539\uff0c\u4f7f\u7528\u4e86&nbsp;<code>fail-fas<\/code>&nbsp;t\u673a\u5236\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>private void writeObject(java.io.ObjectOutputStream s)\n    throws java.io.IOException {\n    <em>\/\/ Write out element count, and any hidden stuff<\/em>\n    int expectedModCount = modCount;\n    s.defaultWriteObject();\n\n    <em>\/\/ Write out size as capacity for behavioral compatibility with clone()<\/em>\n    s.writeInt(size);\n\n    <em>\/\/ Write out all elements in the proper order.<\/em>\n    for (int i=0; i&lt;size; i++) {\n        s.writeObject(elementData&#91;i]);\n    }\n\n    if (modCount != expectedModCount) {\n        throw new ConcurrentModificationException();\n    }\n}\n\nprivate void readObject(java.io.ObjectInputStream s)\n    throws java.io.IOException, ClassNotFoundException {\n\n    <em>\/\/ Read in size, and any hidden stuff<\/em>\n    s.defaultReadObject();\n\n    <em>\/\/ Read in capacity<\/em>\n    s.readInt(); <em>\/\/ ignored<\/em>\n\n    if (size &gt; 0) {\n        <em>\/\/ like clone(), allocate array based upon size not capacity<\/em>\n        SharedSecrets.getJavaObjectInputStreamAccess().checkArray(s, Object&#91;].class, size);\n        Object&#91;] elements = new Object&#91;size];\n\n        <em>\/\/ Read in all elements in the proper order.<\/em>\n        for (int i = 0; i &lt; size; i++) {\n            elements&#91;i] = s.readObject();\n        }\n\n        elementData = elements;\n    } else if (size == 0) {\n        elementData = EMPTY_ELEMENTDATA;\n    } else {\n        throw new java.io.InvalidObjectException(\"Invalid size: \" + size);\n    }\n}\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><a target=\"_blank\" rel=\"noreferrer noopener\"><\/a>\u540c\u6b65\u95ee\u9898<\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong>Note that this implementation is not synchronized.<\/strong>&nbsp;If multiple threads access an&nbsp;<code>ArrayList<\/code>&nbsp;instance concurrently, and at least one of the threads modifies the list structurally, it&nbsp;<em>must<\/em>&nbsp;be synchronized externally. (A structural modification is any operation that adds or deletes one or more elements, or explicitly resizes the backing array; merely setting the value of an element is not a structural modification.) This is typically accomplished by synchronizing on some object that naturally encapsulates the list. If no such object exists, the list should be \u201cwrapped\u201d using the&nbsp;<a href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/14\/docs\/api\/java.base\/java\/util\/Collections.html#synchronizedList(java.util.List)\" rel=\"noreferrer noopener\" target=\"_blank\"><code>Collections.synchronizedList<\/code><\/a>&nbsp;method. [2]<\/p><p>\u7ffb\u8bd1\uff1a<\/p><p>\u6ce8\u610f\u5230&nbsp;<code>ArrayList<\/code>&nbsp;\u7684\u5b9e\u73b0\u662f\u4e0d\u540c\u6b65\u7684\uff0c\u5982\u679c\u6709\u591a\u4e2a\u7ebf\u7a0b\u540c\u65f6\u8bbf\u95ee&nbsp;<code>ArrayList<\/code>&nbsp;\u5b9e\u4f8b\uff0c\u5e76\u4e14\u5176\u4e2d\u81f3\u5c11\u6709\u4e00\u4e2a\u7ebf\u7a0b\u6539\u53d8<code>ArrayList<\/code>&nbsp;\u7684\u7ed3\u6784\uff0c\u6b64\u65f6\u5fc5\u987b\u7528\u540c\u6b65\u65b9\u6cd5(\u7ed3\u6784\u4e0a\u7684\u6539\u53d8\u5305\u62ec\u65b0\u589e\u6216\u5220\u9664\u5143\u7d20\uff0c\u6216\u8005\u660e\u663e\u6539\u53d8\u5e95\u5c42\u6570\u7ec4\u5927\u5c0f\uff0c\u4ec5\u4ec5\u7528&nbsp;<code>set()<\/code>\u6539\u53d8\u5176\u4e2d\u4e00\u4e2a\u503c\u4e0d\u662f\u7ed3\u6784\u6027\u4fee\u6539)\uff0c\u5b9e\u73b0\u540c\u6b65\u7684\u65b9\u6cd5\u901a\u5e38\u662f\u7528\u67d0\u4e2a\u7c7b\u5c01\u88c5 list\uff0c\u901a\u5e38\u53ef\u4ee5\u4f7f\u7528&nbsp;<code>Collections.synchronizedList()<\/code>&nbsp;\u65b9\u6cd5<\/p><\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code>List list = Collections.synchronizedList(new ArrayList(...));\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><a target=\"_blank\" rel=\"noreferrer noopener\"><\/a>FAIL FAST<\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>The iterators returned by this class\u2019s&nbsp;<a href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/14\/docs\/api\/java.base\/java\/util\/ArrayList.html#iterator()\" rel=\"noreferrer noopener\" target=\"_blank\"><code>iterator<\/code><\/a>&nbsp;and&nbsp;<a href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/14\/docs\/api\/java.base\/java\/util\/ArrayList.html#listIterator(int)\" rel=\"noreferrer noopener\" target=\"_blank\"><code>listIterator<\/code><\/a>&nbsp;methods are&nbsp;<em>fail-fast<\/em>: if the list is structurally modified at any time after the iterator is created, in any way except through the iterator\u2019s own&nbsp;<a href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/14\/docs\/api\/java.base\/java\/util\/ListIterator.html#remove()\" rel=\"noreferrer noopener\" target=\"_blank\"><code>remove<\/code><\/a>&nbsp;or&nbsp;<a href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/14\/docs\/api\/java.base\/java\/util\/ListIterator.html#add(E)\" rel=\"noreferrer noopener\" target=\"_blank\"><code>add<\/code><\/a>&nbsp;methods, the iterator will throw a&nbsp;<a href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/14\/docs\/api\/java.base\/java\/util\/ConcurrentModificationException.html\" rel=\"noreferrer noopener\" target=\"_blank\"><code>ConcurrentModificationException<\/code><\/a>. Thus, in the face of concurrent modification, the iterator fails quickly and cleanly, rather than risking arbitrary, non-deterministic behavior at an undetermined time in the future.<\/p><p>Note that the fail-fast behavior of an iterator cannot be guaranteed as it is, generally speaking, impossible to make any hard guarantees in the presence of unsynchronized concurrent modification. Fail-fast iterators throw&nbsp;<code>ConcurrentModificationException<\/code>&nbsp;on a best-effort basis. Therefore, it would be wrong to write a program that depended on this exception for its correctness:&nbsp;<em>the fail-fast behavior of iterators should be used only to detect bugs.<\/em>&nbsp;[2]<\/p><p>\u7ffb\u8bd1\uff1a<\/p><p>\u7531&nbsp;<code>iterator<\/code>&nbsp;\u6216&nbsp;<code>listIterator<\/code>&nbsp;\u65b9\u6cd5\u751f\u6210\u7684 iterators\u9075\u4ece&nbsp;<code>fail-fast<\/code>&nbsp;\u89c4\u5219\uff1a\u5982\u679c\u5728\u521b\u5efa\u4e86 iterator \u4e4b\u540e\uff0c list \u88ab\u4ee5\u4efb\u4f55\u65b9\u6cd5\uff08\u9664\u4e86 iterator \u81ea\u8eab\u7684 remove, add \u65b9\u6cd5\uff09\u8fdb\u884c\u7ed3\u6784\u6027\u4fee\u6539\uff0c iterator \u4f1a\u629b\u51fa&nbsp;<code>ConcurrentModificationException<\/code>&nbsp;,\u56e0\u6b64\uff0c\u5f53\u5b58\u5728\u5e76\u884c\u4fee\u6539\u65f6\uff0c iterator \u4f1a\u5feb\u901f\u5931\u8d25\uff0c\u800c\u4e0d\u662f\u5728\u672a\u6765\u4f4d\u7f6e\u7684\u65f6\u95f4\u505a\u51fa\u5192\u9669\u7684\u4f4d\u7f6e\u64cd\u4f5c\u3002<\/p><p>\u9700\u8981\u6ce8\u610f&nbsp;<code>fail-fast<\/code>\u884c\u4e3a \u4e0d\u80fd\u4fdd\u8bc1\u6b63\u5982\u8bbe\u8ba1\u7684\u90a3\u6837\uff0c\u901a\u5e38\u6765\u8bf4\uff0c\u53d1\u751f\u975e\u540c\u6b65\u5e76\u53d1\u4fee\u6539\u65f6\uff0c\u5f88\u96be\u505a\u51fa\u5f3a\u6709\u529b\u7684\u4fdd\u8bc1&nbsp;<code>fail-fast<\/code>\uff0c Fail-fast iterators \u629b\u51fa&nbsp;<code>ConcurrentModificationException<\/code>&nbsp;\u662f\u57fa\u4e8e\u5c3d\u529b\u800c\u4e3a\u7684\u57fa\u7840\u3002\u56e0\u6b64\uff0c\u7f16\u7a0b\u65f6\u57fa\u4e8e\u8fd9\u4e2a exception \u6765\u4fdd\u8bc1\u51c6\u786e\u6027\u662f\u9519\u8bef\u7684\u505a\u6cd5\uff0c fail-fast \u5e94\u8be5\u4ec5\u4ec5\u7528\u6765\u68c0\u6d4b bugs\u3002<\/p><\/blockquote>\n\n\n\n<p>\u4ee3\u7801\u793a\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>List&lt;Integer&gt; list = new ArrayList&lt;&gt;();\nlist.add(null);\nlist.add(null);\nlist.add(2);\n\nIterator&lt;Integer&gt; i = list.iterator();\nlist.remove(1);\ni.next(); <em>\/\/ throw java.util.ConcurrentModificationException<\/em>\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Iterator&lt;Integer&gt; i = list.iterator();\ni.next(); <em>\/\/ it's ok<\/em>\nlist.remove(1); <\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4e4b\u524d\u6709\u5199\u8fc7\u5173\u4e8e&nbsp;ArrayList&nbsp;\u7684\u6e90\u7801\u89e3\u6790\uff0c\u5f53\u65f6\u662f\u57fa\u4e8e JDK8 \u7684\uff0c\u73b0\u5728 JDK11 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29],"tags":[46],"class_list":["post-1207","post","type-post","status-publish","format-standard","hentry","category-java-","tag-java"],"_links":{"self":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/1207"}],"collection":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1207"}],"version-history":[{"count":1,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/1207\/revisions"}],"predecessor-version":[{"id":1208,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/1207\/revisions\/1208"}],"wp:attachment":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1207"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1207"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1207"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}