-
Notifications
You must be signed in to change notification settings - Fork 0
/
3915ef82.1dff2b15.js
1 lines (1 loc) · 9.08 KB
/
3915ef82.1dff2b15.js
1
(window.webpackJsonp=window.webpackJsonp||[]).push([[19],{147:function(e,t,a){"use strict";function n(){return(n=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var a=arguments[t];for(var n in a)Object.prototype.hasOwnProperty.call(a,n)&&(e[n]=a[n])}return e}).apply(this,arguments)}a.d(t,"a",(function(){return n}))},148:function(e,t,a){"use strict";a.d(t,"a",(function(){return O})),a.d(t,"b",(function(){return j}));var n=a(0),r=a.n(n);function i(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function c(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,n)}return a}function b(e){for(var t=1;t<arguments.length;t++){var a=null!=arguments[t]?arguments[t]:{};t%2?c(Object(a),!0).forEach((function(t){i(e,t,a[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):c(Object(a)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))}))}return e}function l(e,t){if(null==e)return{};var a,n,r=function(e,t){if(null==e)return{};var a,n,r={},i=Object.keys(e);for(n=0;n<i.length;n++)a=i[n],t.indexOf(a)>=0||(r[a]=e[a]);return r}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)a=i[n],t.indexOf(a)>=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(r[a]=e[a])}return r}var o=r.a.createContext({}),s=function(e){var t=r.a.useContext(o),a=t;return e&&(a="function"==typeof e?e(t):b(b({},t),e)),a},O=function(e){var t=s(e.components);return r.a.createElement(o.Provider,{value:t},e.children)},p={inlineCode:"code",wrapper:function(e){var t=e.children;return r.a.createElement(r.a.Fragment,{},t)}},d=r.a.forwardRef((function(e,t){var a=e.components,n=e.mdxType,i=e.originalType,c=e.parentName,o=l(e,["components","mdxType","originalType","parentName"]),O=s(a),d=n,j=O["".concat(c,".").concat(d)]||O[d]||p[d]||i;return a?r.a.createElement(j,b(b({ref:t},o),{},{components:a})):r.a.createElement(j,b({ref:t},o))}));function j(e,t){var a=arguments,n=t&&t.mdxType;if("string"==typeof e||n){var i=a.length,c=new Array(i);c[0]=d;var b={};for(var l in t)hasOwnProperty.call(t,l)&&(b[l]=t[l]);b.originalType=e,b.mdxType="string"==typeof e?e:n,c[1]=b;for(var o=2;o<i;o++)c[o]=a[o];return r.a.createElement.apply(null,c)}return r.a.createElement.apply(null,a)}d.displayName="MDXCreateElement"},149:function(e,t,a){"use strict";function n(e,t){if(null==e)return{};var a,n,r={},i=Object.keys(e);for(n=0;n<i.length;n++)a=i[n],t.indexOf(a)>=0||(r[a]=e[a]);return r}a.d(t,"a",(function(){return n}))},94:function(e,t,a){"use strict";a.r(t),a.d(t,"frontMatter",(function(){return c})),a.d(t,"metadata",(function(){return b})),a.d(t,"toc",(function(){return l})),a.d(t,"default",(function(){return s}));var n=a(147),r=a(149),i=(a(0),a(148)),c={id:"ArrayList",title:"ArrayList",sidebar_label:"ArrayList"},b={unversionedId:"Language/Java/List/ArrayList",id:"Language/Java/List/ArrayList",isDocsHomePage:!1,title:"ArrayList",description:"Basics",source:"@site/docs/Language/Java/List/ArrayList.md",slug:"/Language/Java/List/ArrayList",permalink:"/docs/Language/Java/List/ArrayList",version:"current",sidebar_label:"ArrayList",sidebar:"Language",previous:{title:"List Interface",permalink:"/docs/Language/Java/List/Interface"},next:{title:"LinkedList",permalink:"/docs/Language/Java/List/LinkedList"}},l=[{value:"Basics",id:"basics",children:[]},{value:"Methods",id:"methods",children:[]},{value:"Pros/Cons",id:"proscons",children:[]}],o={toc:l};function s(e){var t=e.components,a=Object(r.a)(e,["components"]);return Object(i.b)("wrapper",Object(n.a)({},o,a,{components:t,mdxType:"MDXLayout"}),Object(i.b)("h2",{id:"basics"},"Basics"),Object(i.b)("ul",null,Object(i.b)("li",{parentName:"ul"},"Implemented with ",Object(i.b)("strong",{parentName:"li"},"Array")),Object(i.b)("li",{parentName:"ul"},"Common methods:")),Object(i.b)("h2",{id:"methods"},"Methods"),Object(i.b)("table",null,Object(i.b)("thead",{parentName:"table"},Object(i.b)("tr",{parentName:"thead"},Object(i.b)("th",Object(n.a)({parentName:"tr"},{align:null}),"Method"),Object(i.b)("th",Object(n.a)({parentName:"tr"},{align:"center"}),"Runtime"),Object(i.b)("th",Object(n.a)({parentName:"tr"},{align:"left"}),"Description"),Object(i.b)("th",Object(n.a)({parentName:"tr"},{align:"center"}),"Return Type"))),Object(i.b)("tbody",{parentName:"table"},Object(i.b)("tr",{parentName:"tbody"},Object(i.b)("td",Object(n.a)({parentName:"tr"},{align:null}),"add(E e)"),Object(i.b)("td",Object(n.a)({parentName:"tr"},{align:"center"}),"O(1)"),Object(i.b)("td",Object(n.a)({parentName:"tr"},{align:"left"}),"Appends the specified element to the end of this list."),Object(i.b)("td",Object(n.a)({parentName:"tr"},{align:"center"}),"boolean")),Object(i.b)("tr",{parentName:"tbody"},Object(i.b)("td",Object(n.a)({parentName:"tr"},{align:null}),"add(int index, E element)"),Object(i.b)("td",Object(n.a)({parentName:"tr"},{align:"center"}),"O(N)"),Object(i.b)("td",Object(n.a)({parentName:"tr"},{align:"left"}),"Inserts the specified element at the specified position in this list."),Object(i.b)("td",Object(n.a)({parentName:"tr"},{align:"center"}),"void")),Object(i.b)("tr",{parentName:"tbody"},Object(i.b)("td",Object(n.a)({parentName:"tr"},{align:null}),"clear()"),Object(i.b)("td",Object(n.a)({parentName:"tr"},{align:"center"}),"O(1)?"),Object(i.b)("td",Object(n.a)({parentName:"tr"},{align:"left"}),"Removes all of the elements from this list."),Object(i.b)("td",Object(n.a)({parentName:"tr"},{align:"center"}),"void")),Object(i.b)("tr",{parentName:"tbody"},Object(i.b)("td",Object(n.a)({parentName:"tr"},{align:null}),"contains(Object o)"),Object(i.b)("td",Object(n.a)({parentName:"tr"},{align:"center"}),"O(n)"),Object(i.b)("td",Object(n.a)({parentName:"tr"},{align:"left"}),"Returns true if this list contains the specified element."),Object(i.b)("td",Object(n.a)({parentName:"tr"},{align:"center"}),"boolean")),Object(i.b)("tr",{parentName:"tbody"},Object(i.b)("td",Object(n.a)({parentName:"tr"},{align:null}),"get(int index)"),Object(i.b)("td",Object(n.a)({parentName:"tr"},{align:"center"}),"O(1)"),Object(i.b)("td",Object(n.a)({parentName:"tr"},{align:"left"}),"Returns the element at the specified position in this list."),Object(i.b)("td",Object(n.a)({parentName:"tr"},{align:"center"}),"E")),Object(i.b)("tr",{parentName:"tbody"},Object(i.b)("td",Object(n.a)({parentName:"tr"},{align:null}),"isEmpty()"),Object(i.b)("td",Object(n.a)({parentName:"tr"},{align:"center"}),"O(1)?"),Object(i.b)("td",Object(n.a)({parentName:"tr"},{align:"left"}),"Returns true if this list contains no elements"),Object(i.b)("td",Object(n.a)({parentName:"tr"},{align:"center"}),"boolean")),Object(i.b)("tr",{parentName:"tbody"},Object(i.b)("td",Object(n.a)({parentName:"tr"},{align:null}),"remove(int index)"),Object(i.b)("td",Object(n.a)({parentName:"tr"},{align:"center"}),"O(n)"),Object(i.b)("td",Object(n.a)({parentName:"tr"},{align:"left"}),"Removes the element at the specified position in this list."),Object(i.b)("td",Object(n.a)({parentName:"tr"},{align:"center"}),"E")),Object(i.b)("tr",{parentName:"tbody"},Object(i.b)("td",Object(n.a)({parentName:"tr"},{align:null}),"remove(Object o)"),Object(i.b)("td",Object(n.a)({parentName:"tr"},{align:"center"}),"O(n)"),Object(i.b)("td",Object(n.a)({parentName:"tr"},{align:"left"}),"Removes the first occurrence of the specified element from this list, if it is present."),Object(i.b)("td",Object(n.a)({parentName:"tr"},{align:"center"}),"boolean")),Object(i.b)("tr",{parentName:"tbody"},Object(i.b)("td",Object(n.a)({parentName:"tr"},{align:null}),"size()"),Object(i.b)("td",Object(n.a)({parentName:"tr"},{align:"center"}),"O(1)"),Object(i.b)("td",Object(n.a)({parentName:"tr"},{align:"left"}),"return size"),Object(i.b)("td",Object(n.a)({parentName:"tr"},{align:"center"}),"int")),Object(i.b)("tr",{parentName:"tbody"},Object(i.b)("td",Object(n.a)({parentName:"tr"},{align:null}),"toArray"),Object(i.b)("td",Object(n.a)({parentName:"tr"},{align:"center"}),"O(n)"),Object(i.b)("td",Object(n.a)({parentName:"tr"},{align:"left"}),Object(i.b)("inlineCode",{parentName:"td"},"ArrayList<T> al = new ArrayList<>()")," then call ",Object(i.b)("inlineCode",{parentName:"td"},"al.toArray(new <T>[])")," to convert it to primitive array"),Object(i.b)("td",Object(n.a)({parentName:"tr"},{align:"center"}),Object(i.b)("inlineCode",{parentName:"td"},"<T>[]"))))),Object(i.b)("h2",{id:"proscons"},"Pros/Cons"),Object(i.b)("ul",null,Object(i.b)("li",{parentName:"ul"},"Advantage:",Object(i.b)("ul",{parentName:"li"},Object(i.b)("li",{parentName:"ul"},"calls to get and set take constant time"))),Object(i.b)("li",{parentName:"ul"},"Disadvantage:",Object(i.b)("ul",{parentName:"li"},Object(i.b)("li",{parentName:"ul"},"insertion and removal are expensive unless changes are made at the end of arraylist "),Object(i.b)("li",{parentName:"ul"},"inefficient for search"),Object(i.b)("li",{parentName:"ul"},"notation of capacity (size of underlying array)"),Object(i.b)("li",{parentName:"ul"},"insertion has to be done manually, there is no method written for insertion")))))}s.isMDXComponent=!0}}]);