{"id":92791,"date":"2025-11-30T22:18:31","date_gmt":"2025-11-30T15:18:31","guid":{"rendered":"https:\/\/itviec.com\/blog\/?p=92791"},"modified":"2025-11-30T22:18:35","modified_gmt":"2025-11-30T15:18:35","slug":"java-collection-framework-la-gi","status":"publish","type":"post","link":"https:\/\/itviec.com\/blog\/java-collection-framework-la-gi\/","title":{"rendered":"Java Collection Framework: Chi ti\u1ebft c\u1ea5u tr\u00fac v\u00e0 c\u00e1c best practice"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">N\u1ed9i dung b\u00e0i vi\u1ebft<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/itviec.com\/blog\/java-collection-framework-la-gi\/#So_do_phan_cap_cua_Java_Collection_Framework\" >S\u01a1 \u0111\u1ed3 ph\u00e2n c\u1ea5p c\u1ee7a Java Collection Framework<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/itviec.com\/blog\/java-collection-framework-la-gi\/#Cac_Interfaces_cot_loi_cua_Java_Collection_Framework\" >C\u00e1c Interfaces c\u1ed1t l\u00f5i c\u1ee7a Java Collection Framework&nbsp;<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/itviec.com\/blog\/java-collection-framework-la-gi\/#Cac_lop_trien_khai_implementations_pho_bien_trong_Java_collection_framework\" >C\u00e1c l\u1edbp tri\u1ec3n khai (implementations) ph\u1ed5 bi\u1ebfn trong Java collection framework<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/itviec.com\/blog\/java-collection-framework-la-gi\/#Lop_tien_ich_Collections_cua_Java_collection_framework\" >L\u1edbp ti\u1ec7n \u00edch Collections c\u1ee7a Java collection framework<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/itviec.com\/blog\/java-collection-framework-la-gi\/#Loi_khuyen_de_su_dung_Java_collection_framework_hieu_qua\" >L\u1eddi khuy\u00ean \u0111\u1ec3 s\u1eed d\u1ee5ng Java collection framework hi\u1ec7u qu\u1ea3<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/itviec.com\/blog\/java-collection-framework-la-gi\/#Cac_cau_hoi_thuong_gap\" >C\u00e1c c\u00e2u h\u1ecfi th\u01b0\u1eddng g\u1eb7p<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/itviec.com\/blog\/java-collection-framework-la-gi\/#Ket_luan\" >K\u1ebft lu\u1eadn<\/a><\/li><\/ul><\/nav><\/div>\n\n<p><strong><em>Java Collection Framework (JCF) l\u00e0 m\u1ed9t ki\u1ebfn tr\u00fac n\u1ec1n t\u1ea3ng trong Java, cung c\u1ea5p c\u00e1c l\u1edbp v\u00e0 giao di\u1ec7n \u0111\u01b0\u1ee3c thi\u1ebft k\u1ebf s\u1eb5n \u0111\u1ec3 l\u01b0u tr\u1eef v\u00e0 thao t\u00e1c hi\u1ec7u qu\u1ea3 tr\u00ean c\u00e1c nh\u00f3m \u0111\u1ed1i t\u01b0\u1ee3ng. \u0110i\u1ec3m m\u1ea1nh c\u1ee7a JCF n\u1eb1m \u1edf vi\u1ec7c gi\u00fap l\u1eadp tr\u00ecnh vi\u00ean ti\u1ebft ki\u1ec7m th\u1eddi gian v\u00e0 c\u00f4ng s\u1ee9c: thay v\u00ec t\u1ef1 tri\u1ec3n khai c\u00e1c c\u1ea5u tr\u00fac d\u1eef li\u1ec7u, b\u1ea1n c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng nh\u1eefng gi\u1ea3i ph\u00e1p \u0111\u00e3 \u0111\u01b0\u1ee3c t\u1ed1i \u01b0u h\u00f3a v\u1ec1 hi\u1ec7u n\u0103ng, gi\u00fap \u1ee9ng d\u1ee5ng ch\u1ea1y nhanh h\u01a1n, \u0111\u1ed3ng th\u1eddi gi\u1eef cho m\u00e3 ngu\u1ed3n s\u1ea1ch, g\u1ecdn v\u00e0 d\u1ec5 t\u00e1i s\u1eed d\u1ee5ng.<\/em><\/strong><\/p>\n\n\n\n<p>Tr\u00ean th\u1ef1c t\u1ebf, JCF \u0111\u01b0\u1ee3c \u1ee9ng d\u1ee5ng trong h\u1ea7u h\u1ebft c\u00e1c t\u00e1c v\u1ee5, ch\u1eb3ng h\u1ea1n nh\u01b0 d\u00f9ng List \u0111\u1ec3 qu\u1ea3n l\u00fd gi\u1ecf h\u00e0ng tr\u00ean trang th\u01b0\u01a1ng m\u1ea1i \u0111i\u1ec7n t\u1eed, d\u00f9ng <code>Map<\/code> \u0111\u1ec3 l\u01b0u cache th\u00f4ng tin ng\u01b0\u1eddi d\u00f9ng nh\u1eb1m t\u0103ng t\u1ed1c \u0111\u1ed9 truy xu\u1ea5t, hay s\u1eed d\u1ee5ng <code>Queue<\/code> \u0111\u1ec3 x\u1ebfp h\u00e0ng c\u00e1c t\u00e1c v\u1ee5 c\u1ea7n x\u1eed l\u00fd theo th\u1ee9 t\u1ef1.<\/p>\n\n\n\n<p><strong>\u0110\u1ecdc b\u00e0i vi\u1ebft n\u00e0y \u0111\u1ec3 hi\u1ec3u th\u00eam v\u1ec1:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>C\u00e1c interfaces c\u1ed1t l\u00f5i c\u1ee7a Framework<\/li>\n\n\n\n<li>S\u01a1 \u0111\u1ed3 ph\u00e2n c\u1ea5p c\u1ee7a Java Collection Framework<\/li>\n\n\n\n<li>C\u00e1c L\u1edbp Implementations Ph\u1ed5 Bi\u1ebfn Nh\u1ea5t<\/li>\n\n\n\n<li>L\u1edbp ti\u1ec7n \u00edch c\u1ee7a collection<\/li>\n\n\n\n<li>L\u1eddi khuy\u00ean v\u00e0 th\u1ef1c h\u00e0nh v\u1edbi Java Collection Framework<\/li>\n\n\n\n<li>C\u00e1c c\u00e2u h\u1ecfi th\u01b0\u1eddng g\u1eb7p<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-s\u01a1-d\u1ed3-phan-c\u1ea5p-c\u1ee7a-java-collection-framework\"><span class=\"ez-toc-section\" id=\"So_do_phan_cap_cua_Java_Collection_Framework\"><\/span><strong>S\u01a1 \u0111\u1ed3 ph\u00e2n c\u1ea5p c\u1ee7a Java Collection Framework<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"787\" height=\"684\" src=\"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/11\/image-3.png\" alt=\"\" class=\"wp-image-92792\" srcset=\"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/11\/image-3.png 787w, https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/11\/image-3-300x261.png 300w, https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/11\/image-3-640x556.png 640w, https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/11\/image-3-200x174.png 200w, https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/11\/image-3-768x667.png 768w\" sizes=\"auto, (max-width: 787px) 100vw, 787px\" \/><figcaption class=\"wp-element-caption\"><em>S\u01a1 \u0111\u1ed3 ph\u00e2n c\u1ea5p c\u1ee7a Java Collection Framework<\/em><\/figcaption><\/figure>\n\n\n\n<p>S\u01a1 \u0111\u1ed3 ph\u00e2n c\u1ea5p c\u1ee7a Java Collection Framework (JCF) th\u1ec3 hi\u1ec7n hai nh\u00f3m th\u00e0nh ph\u1ea7n ch\u00ednh:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>H\u00ecnh ch\u1eef nh\u1eadt xanh<\/strong>: \u0110\u00e2y l\u00e0 c\u00e1c <strong>Interfaces<\/strong>. Ch\u00fang \u0111\u1ecbnh ngh\u0129a c\u00e1c h\u00e0nh vi, quy t\u1eafc v\u00e0 b\u1ed9 ph\u01b0\u01a1ng th\u1ee9c m\u00e0 m\u1ed9t collection ph\u1ea3i c\u00f3, nh\u01b0ng kh\u00f4ng cung c\u1ea5p m\u00e3 ngu\u1ed3n tri\u1ec3n khai c\u1ee5 th\u1ec3. Ch\u00fang l\u00e0 &#8220;khu\u00f4n m\u1eabu&#8221; cho c\u00e1c collection.<\/li>\n\n\n\n<li><strong>H\u00ecnh ch\u1eef nh\u1eadt cam<\/strong>: \u0110\u00e2y l\u00e0 c\u00e1c <strong>Classes<\/strong> (l\u1edbp tri\u1ec3n khai c\u1ee5 th\u1ec3). Ch\u00fang l\u00e0 c\u00e1c l\u1edbp cung c\u1ea5p m\u00e3 ngu\u1ed3n hi\u1ec7n th\u1ef1c h\u00f3a c\u00e1c h\u00e0nh vi \u0111\u01b0\u1ee3c \u0111\u1ecbnh ngh\u0129a trong c\u00e1c Interfaces. Khi l\u1eadp tr\u00ecnh, ch\u00fang ta s\u1ebd kh\u1edfi t\u1ea1o \u0111\u1ed1i t\u01b0\u1ee3ng t\u1eeb c\u00e1c class n\u00e0y.<\/li>\n<\/ul>\n\n\n\n<p>M\u0169i t\u00ean trong s\u01a1 \u0111\u1ed3 bi\u1ec3u th\u1ecb m\u1ed1i quan h\u1ec7:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>M\u0169i t\u00ean li\u1ec1n (Solid Arrow)<\/strong>: Bi\u1ec3u th\u1ecb s\u1ef1 <strong>k\u1ebf th\u1eeba (extends)<\/strong>. V\u00ed d\u1ee5, <code>Collection<\/code> k\u1ebf th\u1eeba t\u1eeb <code>Iterable<\/code>, ngh\u0129a l\u00e0 <code>Collection<\/code> c\u00f3 t\u1ea5t c\u1ea3 c\u00e1c t\u00ednh n\u0103ng c\u1ee7a <code>Iterable<\/code> v\u00e0 m\u1edf r\u1ed9ng th\u00eam.<\/li>\n\n\n\n<li><strong>M\u0169i t\u00ean \u0111\u1ee9t (Dotted Arrow)<\/strong>: Bi\u1ec3u th\u1ecb s\u1ef1 <strong>tri\u1ec3n khai (implements)<\/strong>. V\u00ed d\u1ee5, <code>ArrayList<\/code> tri\u1ec3n khai <code>List<\/code>, ngh\u0129a l\u00e0 <code>ArrayList<\/code> cung c\u1ea5p m\u00e3 ngu\u1ed3n c\u1ee5 th\u1ec3 cho t\u1ea5t c\u1ea3 c\u00e1c ph\u01b0\u01a1ng th\u1ee9c \u0111\u01b0\u1ee3c List interface y\u00eau c\u1ea7u.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-phan-tich-chi-ti\u1ebft-theo-c\u1ea5p-b\u1eadc\"><strong>Ph\u00e2n t\u00edch chi ti\u1ebft theo c\u1ea5p b\u1eadc<\/strong><\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>C\u1ea5p g\u1ed1c (The Root)<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Iterable<\/strong>: \u0110\u00e2y l\u00e0 interface g\u1ed1c c\u1ee7a to\u00e0n b\u1ed9 framework. B\u1ea5t k\u1ef3 \u0111\u1ed1i t\u01b0\u1ee3ng n\u00e0o tri\u1ec3n khai <code>Iterable<\/code> \u0111\u1ec1u c\u00f3 kh\u1ea3 n\u0103ng cho ph\u00e9p ch\u00fang ta duy\u1ec7t qua c\u00e1c ph\u1ea7n t\u1eed c\u1ee7a n\u00f3, \u0111i\u1ec3n h\u00ecnh nh\u1ea5t l\u00e0 b\u1eb1ng v\u00f2ng l\u1eb7p <code>for-each<\/code>.<\/li>\n\n\n\n<li><strong>Collection<\/strong>: Interface n\u00e0y k\u1ebf th\u1eeba t\u1eeb <code>Iterable<\/code> v\u00e0 l\u00e0 &#8220;x\u01b0\u01a1ng s\u1ed1ng&#8221; cho h\u1ea7u h\u1ebft c\u00e1c c\u1ea5u tr\u00fac d\u1eef li\u1ec7u. N\u00f3 \u0111\u1ecbnh ngh\u0129a c\u00e1c ph\u01b0\u01a1ng th\u1ee9c c\u01a1 b\u1ea3n nh\u1ea5t nh\u01b0 <code>add()<\/code>, <code>remove()<\/code>, <code>size()<\/code>, <code>contains()<\/code>, v.v.<\/li>\n<\/ul>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>C\u00e1c nh\u00e1nh ch\u00ednh (The Main Branches)<\/strong><\/li>\n<\/ol>\n\n\n\n<p>T\u1eeb <code>Collection<\/code>, framework \u0111\u01b0\u1ee3c chia th\u00e0nh ba nh\u00e1nh ch\u00ednh, m\u1ed7i nh\u00e1nh c\u00f3 m\u1ed9t \u0111\u1eb7c t\u00ednh ri\u00eang bi\u1ec7t: <code>List<\/code>, <code>Set<\/code>, v\u00e0 <code>Queue<\/code>.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Nh\u00e1nh <code>List <\/code>(Danh s\u00e1ch c\u00f3 th\u1ee9 t\u1ef1): <\/strong>L\u01b0u tr\u1eef m\u1ed9t t\u1eadp h\u1ee3p c\u00e1c ph\u1ea7n t\u1eed c\u00f3 th\u1ee9 t\u1ef1 v\u00e0 cho ph\u00e9p tr\u00f9ng l\u1eb7p. B\u1ea1n c\u00f3 th\u1ec3 truy c\u1eadp ph\u1ea7n t\u1eed qua ch\u1ec9 s\u1ed1 (index).<br>C\u00e1c l\u1edbp tri\u1ec3n khai ph\u1ed5 bi\u1ebfn:\n<ul class=\"wp-block-list\">\n<li><code>ArrayList<\/code>: Tri\u1ec3n khai d\u1ef1a tr\u00ean m\u1ea3ng \u0111\u1ed9ng (dynamic array). R\u1ea5t nhanh cho vi\u1ec7c truy c\u1eadp ng\u1eabu nhi\u00ean ph\u1ea7n t\u1eed (d\u00f9ng <code>get(index)<\/code>).<\/li>\n\n\n\n<li><code>LinkedList<\/code>: Tri\u1ec3n khai d\u1ef1a tr\u00ean danh s\u00e1ch li\u00ean k\u1ebft \u0111\u00f4i (doubly-linked list). Nhanh h\u01a1n <code>ArrayList<\/code> trong vi\u1ec7c th\u00eam\/x\u00f3a ph\u1ea7n t\u1eed \u1edf gi\u1eefa danh s\u00e1ch. L\u01b0u \u00fd r\u1eb1ng <code>LinkedList<\/code> c\u0169ng tri\u1ec3n khai c\u1ea3 <code>Deque<\/code>.<\/li>\n\n\n\n<li><code>Vector<\/code>: M\u1ed9t phi\u00ean b\u1ea3n c\u0169 h\u01a1n v\u00e0 \u0111\u1ed3ng b\u1ed9 h\u00f3a (thread-safe) c\u1ee7a <code>ArrayList<\/code>. <code>Stack<\/code> l\u00e0 m\u1ed9t l\u1edbp con c\u1ee7a Vector, ho\u1ea1t \u0111\u1ed9ng theo c\u01a1 ch\u1ebf LIFO (Last-In, First-Out). Ng\u00e0y nay, <code>ArrayDeque<\/code> th\u01b0\u1eddng \u0111\u01b0\u1ee3c \u01b0u ti\u00ean s\u1eed d\u1ee5ng thay cho Stack.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Nh\u00e1nh Set (T\u1eadp h\u1ee3p c\u00e1c ph\u1ea7n t\u1eed duy nh\u1ea5t): <\/strong>L\u01b0u tr\u1eef m\u1ed9t t\u1eadp h\u1ee3p c\u00e1c ph\u1ea7n t\u1eed <strong>duy nh\u1ea5t<\/strong> (kh\u00f4ng tr\u00f9ng l\u1eb7p).<\/li>\n<\/ul>\n\n\n\n<p>C\u00e1c l\u1edbp tri\u1ec3n khai ph\u1ed5 bi\u1ebfn:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>HashSet<\/code>: S\u1eed d\u1ee5ng b\u1ea3ng b\u0103m (hash table) \u0111\u1ec3 l\u01b0u tr\u1eef. Kh\u00f4ng \u0111\u1ea3m b\u1ea3o th\u1ee9 t\u1ef1 c\u00e1c ph\u1ea7n t\u1eed. Cho hi\u1ec7u n\u0103ng r\u1ea5t cao (th\u1eddi gian g\u1ea7n nh\u01b0 kh\u00f4ng \u0111\u1ed5i) cho c\u00e1c thao t\u00e1c c\u01a1 b\u1ea3n.<\/li>\n\n\n\n<li><code>LinkedHashSet<\/code>: K\u1ebf th\u1eeba t\u1eeb HashSet nh\u01b0ng duy tr\u00ec th\u1ee9 t\u1ef1 ch\u00e8n c\u00e1c ph\u1ea7n t\u1eed.<\/li>\n<\/ul>\n\n\n\n<p>Interface con <code>SortedSet<\/code>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u0110\u00e2y l\u00e0 m\u1ed9t <code>Set<\/code> m\u00e0 c\u00e1c ph\u1ea7n t\u1eed lu\u00f4n \u0111\u01b0\u1ee3c duy tr\u00ec theo th\u1ee9 t\u1ef1 \u0111\u01b0\u1ee3c s\u1eafp x\u1ebfp (th\u1ee9 t\u1ef1 t\u1ef1 nhi\u00ean ho\u1eb7c theo Comparator).<\/li>\n\n\n\n<li><code>TreeSet<\/code>: L\u00e0 l\u1edbp tri\u1ec3n khai c\u1ee7a SortedSet, s\u1eed d\u1ee5ng c\u1ea5u tr\u00fac c\u00e2y \u0111\u1ecf-\u0111en (red-black tree) \u0111\u1ec3 \u0111\u1ea3m b\u1ea3o c\u00e1c ph\u1ea7n t\u1eed lu\u00f4n \u0111\u01b0\u1ee3c s\u1eafp x\u1ebfp.<\/li>\n<\/ul>\n\n\n\n<p><strong>C\u00e1c l\u1edbp tri\u1ec3n khai ph\u1ed5 bi\u1ebfn<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Nh\u00e1nh <code>Queue<\/code> (H\u00e0ng \u0111\u1ee3i): <\/strong>D\u00f9ng \u0111\u1ec3 ch\u1ee9a c\u00e1c ph\u1ea7n t\u1eed tr\u01b0\u1edbc khi x\u1eed l\u00fd. Th\u01b0\u1eddng ho\u1ea1t \u0111\u1ed9ng theo nguy\u00ean t\u1eafc <strong>FIFO (First-In, First-Out)<\/strong> &#8211; v\u00e0o tr\u01b0\u1edbc ra tr\u01b0\u1edbc.<\/li>\n<\/ul>\n\n\n\n<p><strong>L\u1edbp tri\u1ec3n khai<\/strong>: PriorityQueue: M\u1ed9t h\u00e0ng \u0111\u1ee3i \u0111\u1eb7c bi\u1ec7t kh\u00f4ng tu\u00e2n theo FIFO, thay v\u00e0o \u0111\u00f3, n\u00f3 s\u1eafp x\u1ebfp c\u00e1c ph\u1ea7n t\u1eed d\u1ef1a tr\u00ean &#8220;\u0111\u1ed9 \u01b0u ti\u00ean&#8221; (th\u1ee9 t\u1ef1 t\u1ef1 nhi\u00ean ho\u1eb7c Comparator).<\/p>\n\n\n\n<p><strong>Interface con <\/strong><strong>Deque<\/strong><strong> (Double-Ended Queue)<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u0110\u00e2y l\u00e0 &#8220;h\u00e0ng \u0111\u1ee3i hai \u0111\u1ea7u&#8221;, cho ph\u00e9p th\u00eam\/x\u00f3a ph\u1ea7n t\u1eed \u1edf c\u1ea3 \u0111\u1ea7u v\u00e0 cu\u1ed1i h\u00e0ng \u0111\u1ee3i. Nh\u1edd v\u1eady, n\u00f3 c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c d\u00f9ng nh\u01b0 m\u1ed9t <code>Queue<\/code> (FIFO) ho\u1eb7c m\u1ed9t <code>Stack<\/code> (LIFO).<\/li>\n\n\n\n<li><code>ArrayDeque<\/code>: L\u00e0 l\u1edbp tri\u1ec3n khai c\u1ee7a <code>Deque<\/code> d\u1ef1a tr\u00ean m\u1ea3ng \u0111\u1ed9ng. \u0110\u00e2y l\u00e0 l\u1ef1a ch\u1ecdn \u0111\u01b0\u1ee3c khuy\u1ebfn ngh\u1ecb cho c\u1ea3 hai nhu c\u1ea7u v\u1ec1 h\u00e0ng \u0111\u1ee3i (queue) v\u00e0 ng\u0103n x\u1ebfp (stack) v\u00ec hi\u1ec7u n\u0103ng cao.<\/li>\n\n\n\n<li><code>LinkedList<\/code>: Nh\u01b0 \u0111\u00e3 \u0111\u1ec1 c\u1eadp, <code>LinkedList<\/code> c\u0169ng tri\u1ec3n khai Deque.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-cac-interfaces-c\u1ed1t-loi-c\u1ee7a-java-collection-framework-nbsp\"><span class=\"ez-toc-section\" id=\"Cac_Interfaces_cot_loi_cua_Java_Collection_Framework\"><\/span><strong>C\u00e1c Interfaces c\u1ed1t l\u00f5i c\u1ee7a Java Collection Framework&nbsp;<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Tr\u1ecdng t\u00e2m c\u1ee7a <a href=\"https:\/\/www.w3schools.com\/java\/java_collections.asp\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>Java Collection Framework<\/strong><\/a> l\u00e0 m\u1ed9t h\u1ec7 th\u1ed1ng c\u00e1c interface c\u1ed1t l\u00f5i, \u0111\u1ecbnh h\u00ecnh n\u00ean c\u1ea5u tr\u00fac v\u00e0 h\u00e0nh vi c\u1ee7a m\u1ecdi collection. Vi\u1ec7c hi\u1ec3u r\u00f5 c\u00e1c interface n\u00e0y l\u00e0 ch\u00eca kh\u00f3a \u0111\u1ec3 s\u1eed d\u1ee5ng framework m\u1ed9t c\u00e1ch hi\u1ec7u qu\u1ea3.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-iterable-interface\"><strong>Iterable Interface<\/strong><\/h3>\n\n\n\n<p>N\u1ec1n t\u1ea3ng c\u1ee7a to\u00e0n b\u1ed9 h\u1ec7 th\u1ed1ng l\u00e0 Iterable, interface g\u1ed1c c\u1ee7a m\u1ecdi collection. N\u00f3 cung c\u1ea5p m\u1ed9t ph\u01b0\u01a1ng th\u1ee9c duy nh\u1ea5t l\u00e0 <code>iterator()<\/code>, cho ph\u00e9p ch\u00fang ta duy\u1ec7t qua t\u1ea5t c\u1ea3 c\u00e1c ph\u1ea7n t\u1eed trong m\u1ed9t collection, \u0111\u00e2y l\u00e0 ch\u1ee9c n\u0103ng c\u01a1 b\u1ea3n v\u00e0 thi\u1ebft y\u1ebfu nh\u1ea5t.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-collection-interface\"><strong>Collection Interface<\/strong><\/h3>\n\n\n\n<p>K\u1ebf th\u1eeba t\u1eeb Iterable, \u0111\u00e2y l\u00e0 interface g\u1ed1c cho h\u1ea7u h\u1ebft c\u00e1c lo\u1ea1i collection (ngo\u1ea1i tr\u1eeb Map). N\u00f3 \u0111\u1ecbnh ngh\u0129a c\u00e1c h\u00e0nh vi v\u00e0 ph\u01b0\u01a1ng th\u1ee9c chung nh\u1ea5t m\u00e0 m\u1ed9t collection c\u1ea7n ph\u1ea3i c\u00f3, ch\u1eb3ng h\u1ea1n nh\u01b0: th\u00eam (<code>add()<\/code>), x\u00f3a (<code>remove()<\/code>), l\u1ea5y k\u00edch th\u01b0\u1edbc (<code>size()<\/code>), x\u00f3a to\u00e0n b\u1ed9 (<code>clear()<\/code>) v\u00e0 ki\u1ec3m tra s\u1ef1 t\u1ed3n t\u1ea1i c\u1ee7a m\u1ed9t ph\u1ea7n t\u1eed (<code>contains()<\/code>).<\/p>\n\n\n\n<p>D\u1ef1a tr\u00ean Collection, ch\u00fang ta c\u00f3 c\u00e1c interface con v\u1edbi nh\u1eefng \u0111\u1eb7c t\u00ednh ri\u00eang bi\u1ec7t:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>List<\/strong><strong> Interface<\/strong>: \u0110\u1ea1i di\u1ec7n cho m\u1ed9t t\u1eadp h\u1ee3p <strong>c\u00f3 th\u1ee9 t\u1ef1<\/strong> v\u00e0 <strong>cho ph\u00e9p c\u00e1c ph\u1ea7n t\u1eed tr\u00f9ng l\u1eb7p<\/strong>. \u0110i\u1ec3m \u0111\u1eb7c tr\u01b0ng nh\u1ea5t c\u1ee7a List l\u00e0 kh\u1ea3 n\u0103ng truy c\u1eadp c\u00e1c ph\u1ea7n t\u1eed th\u00f4ng qua ch\u1ec9 s\u1ed1 (index) gi\u1ed1ng nh\u01b0 m\u1ea3ng, cho ph\u00e9p ki\u1ec3m so\u00e1t ch\u00ednh x\u00e1c v\u1ecb tr\u00ed c\u1ee7a t\u1eebng ph\u1ea7n t\u1eed.<\/li>\n\n\n\n<li><strong>Set<\/strong><strong> Interface<\/strong>: Ng\u01b0\u1ee3c l\u1ea1i v\u1edbi List, Set \u0111\u1ea1i di\u1ec7n cho m\u1ed9t t\u1eadp h\u1ee3p <strong>kh\u00f4ng cho ph\u00e9p c\u00e1c ph\u1ea7n t\u1eed tr\u00f9ng l\u1eb7p<\/strong>. H\u1ea7u h\u1ebft c\u00e1c tri\u1ec3n khai c\u1ee7a Set kh\u00f4ng \u0111\u1ea3m b\u1ea3o th\u1ee9 t\u1ef1 c\u1ee7a c\u00e1c ph\u1ea7n t\u1eed. Set r\u1ea5t h\u1eefu \u00edch khi b\u1ea1n ch\u1ec9 quan t\u00e2m \u0111\u1ebfn s\u1ef1 t\u1ed3n t\u1ea1i c\u1ee7a m\u1ed9t ph\u1ea7n t\u1eed m\u00e0 kh\u00f4ng c\u1ea7n bi\u1ebft n\u00f3 xu\u1ea5t hi\u1ec7n bao nhi\u00eau l\u1ea7n.<\/li>\n\n\n\n<li><strong>Queue<\/strong><strong> Interface<\/strong>: \u0110\u01b0\u1ee3c thi\u1ebft k\u1ebf \u0111\u1ec3 x\u1eed l\u00fd c\u00e1c ph\u1ea7n t\u1eed theo m\u1ed9t th\u1ee9 t\u1ef1 c\u1ee5 th\u1ec3. Queue ho\u1ea1t \u0111\u1ed9ng theo nguy\u00ean t\u1eafc <strong>First-In, First-Out (FIFO)<\/strong> \u2013 ph\u1ea7n t\u1eed n\u00e0o \u0111\u01b0\u1ee3c th\u00eam v\u00e0o tr\u01b0\u1edbc s\u1ebd \u0111\u01b0\u1ee3c x\u1eed l\u00fd tr\u01b0\u1edbc. N\u00f3 th\u01b0\u1eddng \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng trong c\u00e1c t\u00e1c v\u1ee5 l\u1eadp l\u1ecbch ho\u1eb7c x\u1eed l\u00fd tu\u1ea7n t\u1ef1.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-map-interface\"><strong>Map Interface<\/strong><\/h3>\n\n\n\n<p>\u0110\u1ee9ng t\u00e1ch bi\u1ec7t v\u1edbi h\u1ec7 th\u1ed1ng Collection l\u00e0 <strong>Map<\/strong> Interface. Thay v\u00ec l\u01b0u tr\u1eef c\u00e1c ph\u1ea7n t\u1eed \u0111\u01a1n l\u1ebb, Map l\u01b0u tr\u1eef d\u1eef li\u1ec7u d\u01b0\u1edbi d\u1ea1ng c\u00e1c c\u1eb7p <strong>key-value<\/strong>. M\u1ed7i key trong Map l\u00e0 duy nh\u1ea5t v\u00e0 \u0111\u01b0\u1ee3c d\u00f9ng \u0111\u1ec3 truy xu\u1ea5t value t\u01b0\u01a1ng \u1ee9ng. \u0110\u00e2y l\u00e0 c\u1ea5u tr\u00fac d\u1eef li\u1ec7u l\u00fd t\u01b0\u1edfng khi b\u1ea1n c\u1ea7n t\u00ecm ki\u1ebfm, c\u1eadp nh\u1eadt ho\u1eb7c x\u00f3a m\u1ed9t ph\u1ea7n t\u1eed d\u1ef1a tr\u00ean m\u1ed9t \u0111\u1ecbnh danh duy nh\u1ea5t.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-cac-l\u1edbp-tri\u1ec3n-khai-implementations-ph\u1ed5-bi\u1ebfn-trong-java-collection-framework\"><span class=\"ez-toc-section\" id=\"Cac_lop_trien_khai_implementations_pho_bien_trong_Java_collection_framework\"><\/span><strong>C\u00e1c l\u1edbp tri\u1ec3n khai (implementations) ph\u1ed5 bi\u1ebfn trong Java collection framework<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>N\u1ebfu c\u00e1c interface l\u00e0 b\u1ea3n thi\u1ebft k\u1ebf, th\u00ec c\u00e1c l\u1edbp tri\u1ec3n khai (implementations) ch\u00ednh l\u00e0 nh\u1eefng c\u00f4ng tr\u00ecnh c\u1ee5 th\u1ec3 \u0111\u01b0\u1ee3c x\u00e2y d\u1ef1ng t\u1eeb b\u1ea3n thi\u1ebft k\u1ebf \u0111\u00f3. Vi\u1ec7c l\u1ef1a ch\u1ecdn \u0111\u00fang l\u1edbp tri\u1ec3n khai cho t\u1eebng b\u00e0i to\u00e1n l\u00e0 y\u1ebfu t\u1ed1 quy\u1ebft \u0111\u1ecbnh \u0111\u1ebfn hi\u1ec7u n\u0103ng v\u00e0 s\u1ef1 hi\u1ec7u qu\u1ea3 c\u1ee7a ch\u01b0\u01a1ng tr\u00ecnh.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-tri\u1ec3n-khai-c\u1ee7a-list-interface-arraylist-vs-linkedlist\"><strong>Tri\u1ec3n khai c\u1ee7a List Interface: <\/strong><strong>ArrayList<\/strong><strong> vs. <\/strong><strong>LinkedList<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>Ti\u00eau ch\u00ed&nbsp;<\/strong><\/td><td><strong>ArrayList<\/strong><\/td><td><strong>LinkedList<\/strong><\/td><\/tr><tr><td><strong>C\u1ea5u tr\u00fac D\u1eef li\u1ec7u<\/strong><\/td><td>D\u1ef1a tr\u00ean m\u1ea3ng (array) c\u00f3 th\u1ec3 thay \u0111\u1ed5i k\u00edch th\u01b0\u1edbc.<\/td><td>D\u1ef1a tr\u00ean danh s\u00e1ch li\u00ean k\u1ebft k\u00e9p (m\u1ed7i ph\u1ea7n t\u1eed tr\u1ecf t\u1edbi ph\u1ea7n t\u1eed tr\u01b0\u1edbc v\u00e0 sau n\u00f3)<\/td><\/tr><tr><td><strong>Truy xu\u1ea5t ph\u1ea7n t\u1eed (get)<\/strong><\/td><td>R\u1ea5t nhanh (O(1)). Truy c\u1eadp tr\u1ef1c ti\u1ebfp qua ch\u1ec9 s\u1ed1 (index).<\/td><td>Ch\u1eadm (O(n)). Ph\u1ea3i duy\u1ec7t t\u1eeb \u0111\u1ea7u\/cu\u1ed1i danh s\u00e1ch \u0111\u1ec3 t\u00ecm ph\u1ea7n t\u1eed.<\/td><\/tr><tr><td><strong>Th\u00eam\/X\u00f3a ph\u1ea7n t\u1eed<\/strong><\/td><td>Ch\u1eadm (O(n)). Ph\u1ea3i d\u1ecbch chuy\u1ec3n t\u1ea5t c\u1ea3 c\u00e1c ph\u1ea7n t\u1eed ph\u00eda sau.<\/td><td>R\u1ea5t nhanh (O(1)). Ch\u1ec9 c\u1ea7n thay \u0111\u1ed5i c\u00e1c con tr\u1ecf li\u00ean k\u1ebft.<\/td><\/tr><tr><td><strong>S\u1eed d\u1ee5ng B\u1ed9 nh\u1edb<\/strong><\/td><td>Hi\u1ec7u qu\u1ea3 h\u01a1n, ch\u1ec9 l\u01b0u tr\u1eef d\u1eef li\u1ec7u trong m\u1ea3ng.<\/td><td>T\u1ed1n nhi\u1ec1u b\u1ed9 nh\u1edb h\u01a1n do m\u1ed7i ph\u1ea7n t\u1eed ph\u1ea3i l\u01b0u th\u00eam con tr\u1ecf next v\u00e0 prev.<\/td><\/tr><tr><td><strong>Tr\u01b0\u1eddng h\u1ee3p s\u1eed d\u1ee5ng t\u1ed1t nh\u1ea5t<\/strong><\/td><td>Khi \u1ee9ng d\u1ee5ng c\u1ee7a b\u1ea1n c\u00f3 nhu c\u1ea7u \u0111\u1ecdc v\u00e0 truy c\u1eadp d\u1eef li\u1ec7u th\u01b0\u1eddng xuy\u00ean h\u01a1n l\u00e0 ch\u1ec9nh s\u1eeda.<\/td><td>Khi \u1ee9ng d\u1ee5ng c\u1ee7a b\u1ea1n y\u00eau c\u1ea7u th\u00eam v\u00e0 x\u00f3a ph\u1ea7n t\u1eed li\u00ean t\u1ee5c, \u0111\u1eb7c bi\u1ec7t l\u00e0 \u1edf \u0111\u1ea7u\/cu\u1ed1i danh s\u00e1ch.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-tri\u1ec3n-khai-c\u1ee7a-set-interface-hashset-linkedhashset-va-treeset\"><strong>Tri\u1ec3n khai c\u1ee7a Set Interface: <\/strong><strong>HashSet<\/strong><strong>, <\/strong><strong>LinkedHashSet<\/strong><strong>, v\u00e0 <\/strong><strong>TreeSet<\/strong><\/h3>\n\n\n\n<p>Khi b\u1ea1n c\u1ea7n m\u1ed9t t\u1eadp h\u1ee3p ch\u1ec9 ch\u1ee9a c\u00e1c ph\u1ea7n t\u1eed duy nh\u1ea5t, Set l\u00e0 l\u1ef1a ch\u1ecdn h\u00e0ng \u0111\u1ea7u.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-hashset\"><strong>HashSet<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>L\u01b0u tr\u1eef: \u0110\u00e2y l\u00e0 l\u1edbp tri\u1ec3n khai ph\u1ed5 bi\u1ebfn v\u00e0 hi\u1ec7u n\u0103ng nh\u1ea5t. N\u00f3 s\u1eed d\u1ee5ng m\u1ed9t <code>HashMap<\/code> \u1edf b\u00ean d\u01b0\u1edbi \u0111\u1ec3 l\u01b0u tr\u1eef c\u00e1c ph\u1ea7n t\u1eed.<\/li>\n\n\n\n<li>\u0110\u1eb7c \u0111i\u1ec3m: N\u00f3 kh\u00f4ng \u0111\u1ea3m b\u1ea3o th\u1ee9 t\u1ef1 c\u1ee7a c\u00e1c ph\u1ea7n t\u1eed. Khi b\u1ea1n duy\u1ec7t qua m\u1ed9t <code>HashSet<\/code>, th\u1ee9 t\u1ef1 c\u00f3 th\u1ec3 thay \u0111\u1ed5i gi\u1eefa c\u00e1c l\u1ea7n ch\u1ea1y.<\/li>\n\n\n\n<li>Hi\u1ec7u n\u0103ng: Cung c\u1ea5p hi\u1ec7u n\u0103ng t\u1ed1t nh\u1ea5t cho c\u00e1c thao t\u00e1c th\u00eam (<code>add<\/code>), x\u00f3a (<code>remove<\/code>), v\u00e0 ki\u1ec3m tra (<code>contains<\/code>) v\u1edbi \u0111\u1ed9 ph\u1ee9c t\u1ea1p trung b\u00ecnh l\u00e0 O(1).<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-linkedhashset\"><strong>LinkedHashSet<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>L\u01b0u tr\u1eef: L\u1edbp n\u00e0y k\u1ebf th\u1eeba <code>HashSet<\/code> nh\u01b0ng b\u1ed5 sung th\u00eam m\u1ed9t danh s\u00e1ch li\u00ean k\u1ebft \u0111\u1ec3 k\u1ebft n\u1ed1i c\u00e1c ph\u1ea7n t\u1eed.<\/li>\n\n\n\n<li>\u0110\u1eb7c \u0111i\u1ec3m: S\u1ef1 k\u1ebft h\u1ee3p n\u00e0y mang l\u1ea1i \u0111i\u1ec1u t\u1ed1t nh\u1ea5t c\u1ee7a c\u1ea3 hai: hi\u1ec7u n\u0103ng O(1) c\u1ee7a <code>HashSet<\/code> v\u00e0 kh\u1ea3 n\u0103ng duy tr\u00ec th\u1ee9 t\u1ef1 c\u00e1c ph\u1ea7n t\u1eed khi \u0111\u01b0\u1ee3c th\u00eam v\u00e0o (insertion-order).<\/li>\n\n\n\n<li>Khi n\u00e0o n\u00ean d\u00f9ng: Khi b\u1ea1n c\u1ea7n s\u1ef1 duy nh\u1ea5t c\u1ee7a <code>Set<\/code> nh\u01b0ng v\u1eabn mu\u1ed1n duy\u1ec7t qua c\u00e1c ph\u1ea7n t\u1eed theo \u0111\u00fang th\u1ee9 t\u1ef1 b\u1ea1n \u0111\u00e3 th\u00eam ch\u00fang.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-treeset-nbsp\"><strong>TreeSet<\/strong><strong>&nbsp;<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>L\u01b0u tr\u1eef: <code>TreeSet<\/code> s\u1eed d\u1ee5ng c\u1ea5u tr\u00fac c\u00e2y \u0111\u1ecf-\u0111en (Red-Black Tree) \u0111\u1ec3 l\u01b0u tr\u1eef d\u1eef li\u1ec7u.<\/li>\n\n\n\n<li>\u0110\u1eb7c \u0111i\u1ec3m: \u0110i\u1ec3m \u0111\u1eb7c tr\u01b0ng nh\u1ea5t c\u1ee7a <code>TreeSet<\/code> l\u00e0 n\u00f3 lu\u00f4n gi\u1eef cho c\u00e1c ph\u1ea7n t\u1eed \u0111\u01b0\u1ee3c s\u1eafp x\u1ebfp. C\u00e1c ph\u1ea7n t\u1eed s\u1ebd \u0111\u01b0\u1ee3c s\u1eafp x\u1ebfp theo th\u1ee9 t\u1ef1 t\u1ef1 nhi\u00ean (v\u00ed d\u1ee5: s\u1ed1 t\u0103ng d\u1ea7n, ch\u1eef c\u00e1i theo alphabet) ho\u1eb7c theo m\u1ed9t <code>Comparator<\/code> do b\u1ea1n \u0111\u1ecbnh ngh\u0129a.<\/li>\n\n\n\n<li>Hi\u1ec7u n\u0103ng: C\u00e1c thao t\u00e1c c\u01a1 b\u1ea3n c\u00f3 \u0111\u1ed9 ph\u1ee9c t\u1ea1p l\u00e0 O(log n), ch\u1eadm h\u01a1n HashSet nh\u01b0ng \u0111\u1ed5i l\u1ea1i b\u1ea1n c\u00f3 m\u1ed9t t\u1eadp h\u1ee3p lu\u00f4n \u0111\u01b0\u1ee3c s\u1eafp x\u1ebfp.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-tri\u1ec3n-khai-c\u1ee7a-map-interface-hashmap-linkedhashmap-va-treemap\"><strong>Tri\u1ec3n khai c\u1ee7a Map Interface: <\/strong><strong>HashMap<\/strong><strong>, <\/strong><strong>LinkedHashMap<\/strong><strong>, v\u00e0 <\/strong><strong>TreeMap<\/strong><\/h3>\n\n\n\n<p><code>Map<\/code> \u0111\u01b0\u1ee3c d\u00f9ng \u0111\u1ec3 l\u01b0u tr\u1eef d\u1eef li\u1ec7u d\u01b0\u1edbi d\u1ea1ng c\u00e1c c\u1eb7p kh\u00f3a-gi\u00e1 tr\u1ecb (key-value).<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-hashmap\"><strong>HashMap<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>L\u01b0u tr\u1eef: \u0110\u00e2y l\u00e0 l\u1edbp tri\u1ec3n khai ti\u00eau chu\u1ea9n v\u00e0 \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng nhi\u1ec1u nh\u1ea5t cho <code>Map<\/code>. N\u00f3 \u0111\u01b0\u1ee3c x\u00e2y d\u1ef1ng d\u1ef1a tr\u00ean m\u1ed9t b\u1ea3ng b\u0103m.<\/li>\n\n\n\n<li>\u0110\u1eb7c \u0111i\u1ec3m: <code>HashMap<\/code> kh\u00f4ng \u0111\u1ea3m b\u1ea3o th\u1ee9 t\u1ef1 c\u1ee7a c\u00e1c c\u1eb7p key-value. N\u00f3 cho ph\u00e9p m\u1ed9t <code>key<\/code> l\u00e0 <code>null<\/code> v\u00e0 nhi\u1ec1u <code>value<\/code> l\u00e0 <code>null<\/code>.<\/li>\n\n\n\n<li>Hi\u1ec7u n\u0103ng: Gi\u1ed1ng nh\u01b0 <code>HashSet<\/code>, n\u00f3 cho hi\u1ec7u n\u0103ng trung b\u00ecnh O(1) cho c\u00e1c thao t\u00e1c <code>put<\/code> v\u00e0 <code>get<\/code>. \u0110\u00e2y l\u00e0 l\u1ef1a ch\u1ecdn m\u1eb7c \u0111\u1ecbnh khi b\u1ea1n c\u1ea7n m\u1ed9t <code>Map<\/code>.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-linkedhashmap\"><strong>LinkedHashMap<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u0110\u1eb7c \u0111i\u1ec3m: K\u1ebf th\u1eeba t\u1eeb <code>HashMap<\/code>, <code>LinkedHashMap<\/code> b\u1ed5 sung kh\u1ea3 n\u0103ng duy tr\u00ec th\u1ee9 t\u1ef1 ch\u00e8n (insertion-order) c\u1ee7a c\u00e1c c\u1eb7p key-value, t\u01b0\u01a1ng t\u1ef1 nh\u01b0 <code>LinkedHashSet<\/code>.<\/li>\n\n\n\n<li>Khi n\u00e0o n\u00ean d\u00f9ng? R\u1ea5t h\u1eefu \u00edch khi b\u1ea1n c\u1ea7n duy\u1ec7t qua c\u00e1c entry trong <code>Map<\/code> theo \u0111\u00fang th\u1ee9 t\u1ef1 ch\u00fang \u0111\u00e3 \u0111\u01b0\u1ee3c th\u00eam v\u00e0o, v\u00ed d\u1ee5 nh\u01b0 x\u00e2y d\u1ef1ng m\u1ed9t b\u1ed9 nh\u1edb \u0111\u1ec7m (cache) LRU.<\/li>\n<\/ul>\n\n\n\n<p><code>TreeMap<\/code> SortedMap sortedMap = new TreeMap&lt;&gt;();<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ S\u1eafp x\u1ebfp c\u00e1c c\u1eb7p key-value d\u1ef1a tr\u00ean key.\nMap&lt;String, Integer&gt; treeMap = new TreeMap&lt;&gt;();\ntreeMap.put(\"C\", 3);\ntreeMap.put(\"A\", 1);\ntreeMap.put(\"B\", 2);\n\/\/ Khi duy\u1ec7t qua, output s\u1ebd l\u00e0 A, B, C\nSystem.out.println(treeMap); \/\/ {A=1, B=2, C=3}<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>L\u01b0u tr\u1eef: <code>TreeMap<\/code> l\u01b0u tr\u1eef c\u00e1c entry trong m\u1ed9t c\u00e2y \u0111\u1ecf-\u0111en, t\u01b0\u01a1ng t\u1ef1 nh\u01b0 <code>TreeSet<\/code>.<\/li>\n\n\n\n<li>\u0110\u1eb7c \u0111i\u1ec3m: N\u00f3 s\u1eafp x\u1ebfp c\u00e1c c\u1eb7p key-value d\u1ef1a tr\u00ean key. C\u00e1c key ph\u1ea3i c\u00f3 kh\u1ea3 n\u0103ng so s\u00e1nh \u0111\u01b0\u1ee3c (tri\u1ec3n khai <code>Comparable<\/code>) ho\u1eb7c b\u1ea1n ph\u1ea3i cung c\u1ea5p m\u1ed9t <code>Comparator<\/code>.<\/li>\n\n\n\n<li>Khi n\u00e0o n\u00ean d\u00f9ng? Khi b\u1ea1n c\u00f3 nhu c\u1ea7u l\u1ea5y ra c\u00e1c entry t\u1eeb <code>Map<\/code> theo m\u1ed9t th\u1ee9 t\u1ef1 \u0111\u00e3 \u0111\u01b0\u1ee3c s\u1eafp x\u1ebfp c\u1ee7a c\u00e1c key.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-l\u1edbp-ti\u1ec7n-ich-collections-c\u1ee7a-java-collection-framework\"><span class=\"ez-toc-section\" id=\"Lop_tien_ich_Collections_cua_Java_collection_framework\"><\/span><strong>L\u1edbp ti\u1ec7n \u00edch Collections c\u1ee7a Java collection framework<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Ngo\u00e0i c\u00e1c interface v\u00e0 l\u1edbp tri\u1ec3n khai, Java Collection Framework c\u00f2n cung c\u1ea5p m\u1ed9t b\u1ed9 c\u00f4ng c\u1ee5 m\u1ea1nh m\u1ebd l\u00e0 l\u1edbp ti\u1ec7n \u00edch Collections. \u0110\u1ed3ng th\u1eddi, vi\u1ec7c hi\u1ec3u c\u00e1c c\u00e1ch duy\u1ec7t qua ph\u1ea7n t\u1eed s\u1ebd gi\u00fap b\u1ea1n x\u1eed l\u00fd d\u1eef li\u1ec7u m\u1ed9t c\u00e1ch linh ho\u1ea1t v\u00e0 hi\u1ec7u qu\u1ea3.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-l\u1edbp-ti\u1ec7n-ich-collections\"><strong>L\u1edbp ti\u1ec7n \u00edch <\/strong><strong>Collections<\/strong><\/h3>\n\n\n\n<p>\u0110\u1eebng nh\u1ea7m l\u1eabn v\u1edbi interface Collection (kh\u00f4ng c\u00f3 &#8216;s&#8217;), <strong>l\u1edbp ti\u1ec7n \u00edch Collections <\/strong>(c\u00f3 &#8216;s&#8217; \u1edf cu\u1ed1i) l\u00e0 m\u1ed9t l\u1edbp ch\u1ee9a \u0111\u1ea7y c\u00e1c ph\u01b0\u01a1ng th\u1ee9c <code>static<\/code> h\u1eefu \u00edch \u0111\u1ec3 th\u1ef1c hi\u1ec7n c\u00e1c thao t\u00e1c ph\u1ed5 bi\u1ebfn tr\u00ean collection, \u0111\u1eb7c bi\u1ec7t l\u00e0 <code>List<\/code>.<\/p>\n\n\n\n<p>D\u01b0\u1edbi \u0111\u00e2y l\u00e0 m\u1ed9t s\u1ed1 ph\u01b0\u01a1ng th\u1ee9c quan tr\u1ecdng m\u00e0 b\u1ea1n s\u1ebd th\u01b0\u1eddng xuy\u00ean s\u1eed d\u1ee5ng:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>sort(List&lt;T&gt; list)<\/strong>: S\u1eafp x\u1ebfp c\u00e1c ph\u1ea7n t\u1eed trong m\u1ed9t <code>List<\/code> theo th\u1ee9 t\u1ef1 t\u1ef1 nhi\u00ean c\u1ee7a ch\u00fang. \u0110\u00e2y l\u00e0 m\u1ed9t trong nh\u1eefng ph\u01b0\u01a1ng th\u1ee9c \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng nhi\u1ec1u nh\u1ea5t.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>List&lt;Integer&gt; numbers = new ArrayList&lt;&gt;(Arrays.asList(5, 2, 8, 1));\nCollections.sort(numbers);\n\/\/ numbers b\u00e2y gi\u1edd l\u00e0 &#91;1, 2, 5, 8]<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>shuffle(List&lt;?&gt; list)<\/strong>: X\u00e1o tr\u1ed9n ng\u1eabu nhi\u00ean v\u1ecb tr\u00ed c\u1ee7a c\u00e1c ph\u1ea7n t\u1eed trong <code>List<\/code>. R\u1ea5t h\u1eefu \u00edch khi b\u1ea1n c\u1ea7n t\u1ea1o ra s\u1ef1 ng\u1eabu nhi\u00ean, v\u00ed d\u1ee5 nh\u01b0 trong m\u1ed9t tr\u00f2 ch\u01a1i r\u00fat b\u00e0i.<\/li>\n\n\n\n<li><strong>reverse(List&lt;?&gt; list)<\/strong>: \u0110\u1ea3o ng\u01b0\u1ee3c th\u1ee9 t\u1ef1 c\u00e1c ph\u1ea7n t\u1eed trong <code>List<\/code>. Ph\u1ea7n t\u1eed cu\u1ed1i c\u00f9ng s\u1ebd tr\u1edf th\u00e0nh \u0111\u1ea7u ti\u00ean v\u00e0 ng\u01b0\u1ee3c l\u1ea1i.<\/li>\n\n\n\n<li><strong>binarySearch(List&lt;?&gt; list, T key)<\/strong>: T\u00ecm ki\u1ebfm m\u1ed9t ph\u1ea7n t\u1eed tr\u00ean m\u1ed9t <code>List<\/code> <strong>\u0111\u00e3 \u0111\u01b0\u1ee3c s\u1eafp x\u1ebfp<\/strong> b\u1eb1ng thu\u1eadt to\u00e1n t\u00ecm ki\u1ebfm nh\u1ecb ph\u00e2n. Ph\u01b0\u01a1ng th\u1ee9c n\u00e0y cho hi\u1ec7u n\u0103ng r\u1ea5t cao (O(log n)).<\/li>\n\n\n\n<li><strong>max(Collection&lt;?&gt; coll)<\/strong><strong> v\u00e0 <\/strong><strong>min(Collection&lt;?&gt; coll)<\/strong>: D\u1ec5 d\u00e0ng t\u00ecm th\u1ea5y ph\u1ea7n t\u1eed l\u1edbn nh\u1ea5t ho\u1eb7c nh\u1ecf nh\u1ea5t trong m\u1ed9t collection.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-cac-cach-duy\u1ec7t-qua-m\u1ed9t-collection\"><strong>C\u00e1c c\u00e1ch duy\u1ec7t qua m\u1ed9t Collection<\/strong><\/h3>\n\n\n\n<p>Vi\u1ec7c l\u1eb7p qua c\u00e1c ph\u1ea7n t\u1eed l\u00e0 m\u1ed9t thao t\u00e1c c\u01a1 b\u1ea3n v\u00e0 c\u00f3 nhi\u1ec1u c\u00e1ch \u0111\u1ec3 th\u1ef1c hi\u1ec7n, m\u1ed7i c\u00e1ch c\u00f3 \u01b0u \u0111i\u1ec3m ri\u00eang.<\/p>\n\n\n\n<p><strong>1. V\u00f2ng l\u1eb7p <\/strong><strong>for-each<\/strong><strong> (Enhanced for-loop)<\/strong><\/p>\n\n\n\n<p>\u0110\u00e2y l\u00e0 c\u00e1ch ti\u1ebfp c\u1eadn <strong>\u0111\u01a1n gi\u1ea3n, d\u1ec5 \u0111\u1ecdc v\u00e0 ph\u1ed5 bi\u1ebfn nh\u1ea5t<\/strong>. C\u00fa ph\u00e1p c\u1ee7a n\u00f3 r\u1ea5t g\u1ecdn g\u00e0ng v\u00e0 che gi\u1ea5u \u0111i s\u1ef1 ph\u1ee9c t\u1ea1p c\u1ee7a vi\u1ec7c duy\u1ec7t.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>List&lt;String&gt; fruits = Arrays.asList(\"Apple\", \"Banana\", \"Cherry\");\nfor (String fruit : fruits) {\n    System.out.println(fruit);\n}<\/code><\/pre>\n\n\n\n<p><strong>Khi n\u00e0o n\u00ean d\u00f9ng?<\/strong> H\u1ea7u h\u1ebft c\u00e1c tr\u01b0\u1eddng h\u1ee3p khi b\u1ea1n ch\u1ec9 c\u1ea7n duy\u1ec7t qua c\u00e1c ph\u1ea7n t\u1eed m\u00e0 kh\u00f4ng c\u1ea7n x\u00f3a ch\u00fang.<\/p>\n\n\n\n<p><strong>2. S\u1eed d\u1ee5ng <\/strong><strong>Iterator<\/strong><\/p>\n\n\n\n<p><code>Iterator<\/code> l\u00e0 m\u1ed9t interface cung c\u1ea5p m\u1ed9t c\u00e1ch chu\u1ea9n h\u00f3a \u0111\u1ec3 duy\u1ec7t qua collection. N\u00f3 \u0111\u1eb7c bi\u1ec7t quan tr\u1ecdng v\u00ec cho ph\u00e9p <strong>x\u00f3a ph\u1ea7n t\u1eed m\u1ed9t c\u00e1ch an to\u00e0n ngay trong khi duy\u1ec7t<\/strong>.<\/p>\n\n\n\n<p>Iterator cung c\u1ea5p ba ph\u01b0\u01a1ng th\u1ee9c ch\u00ednh:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>hasNext()<\/code>: Tr\u1ea3 v\u1ec1 true n\u1ebfu c\u00f2n ph\u1ea7n t\u1eed ti\u1ebfp theo.<\/li>\n\n\n\n<li><code>next()<\/code>: Tr\u1ea3 v\u1ec1 ph\u1ea7n t\u1eed ti\u1ebfp theo.<\/li>\n\n\n\n<li><code>remove()<\/code>: X\u00f3a ph\u1ea7n t\u1eed hi\u1ec7n t\u1ea1i m\u00e0 <code>next()<\/code> v\u1eeba tr\u1ea3 v\u1ec1.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>List&lt;Integer&gt; numbers = new ArrayList&lt;&gt;(Arrays.asList(1, 2, 3, 4, 5));\nIterator&lt;Integer&gt; iterator = numbers.iterator();\nwhile (iterator.hasNext()) {\n    Integer number = iterator.next();\n    if (number % 2 == 0) { \/\/ X\u00f3a c\u00e1c s\u1ed1 ch\u1eb5n\n        iterator.remove(); \/\/ An to\u00e0n \u0111\u1ec3 x\u00f3a!\n    }\n}\n\/\/ numbers b\u00e2y gi\u1edd l\u00e0 &#91;1, 3, 5]<\/code><\/pre>\n\n\n\n<p><strong>L\u01b0u \u00fd:<\/strong> C\u1ed1 g\u1eafng x\u00f3a ph\u1ea7n t\u1eed b\u1eb1ng ph\u01b0\u01a1ng th\u1ee9c <code>remove()<\/code> c\u1ee7a collection (<code>numbers.remove(number)<\/code>) b\u00ean trong v\u00f2ng l\u1eb7p for-each s\u1ebd g\u00e2y ra l\u1ed7i <code>ConcurrentModificationException<\/code>.<\/p>\n\n\n\n<p><strong>3. Java 8 Stream API&nbsp;<\/strong><\/p>\n\n\n\n<p>K\u1ec3 t\u1eeb Java 8, Stream API \u0111\u00e3 mang \u0111\u1ebfn m\u1ed9t c\u00e1ch ti\u1ebfp c\u1eadn ho\u00e0n to\u00e0n m\u1edbi, m\u1ea1nh m\u1ebd v\u00e0 linh ho\u1ea1t \u0111\u1ec3 x\u1eed l\u00fd collection. N\u00f3 cho ph\u00e9p b\u1ea1n th\u1ef1c hi\u1ec7n c\u00e1c thao t\u00e1c ph\u1ee9c t\u1ea1p tr\u00ean d\u1eef li\u1ec7u theo m\u1ed9t lu\u1ed3ng (pipeline) m\u1ed9t c\u00e1ch <strong>khai b\u00e1o (declarative)<\/strong>.<\/p>\n\n\n\n<p>Thay v\u00ec vi\u1ebft code n\u00f3i &#8220;l\u00e0m th\u1ebf n\u00e0o&#8221; \u0111\u1ec3 duy\u1ec7t v\u00e0 x\u1eed l\u00fd (nh\u01b0 v\u00f2ng l\u1eb7p <code>for<\/code>), b\u1ea1n ch\u1ec9 c\u1ea7n n\u00f3i &#8220;mu\u1ed1n g\u00ec&#8221;.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>List&lt;String&gt; names = Arrays.asList(\"Alice\", \"Bob\", \"Charlie\", \"Anna\");\n\/\/ L\u1ecdc ra c\u00e1c t\u00ean b\u1eaft \u0111\u1ea7u b\u1eb1ng \"A\", chuy\u1ec3n th\u00e0nh ch\u1eef hoa v\u00e0 in ra\nnames.stream()\n     .filter(name -&gt; name.startsWith(\"A\")) \/\/ L\u1ecdc\n     .map(String::toUpperCase)              \/\/ Bi\u1ebfn \u0111\u1ed5i\n     .forEach(System.out::println);        \/\/ H\u00e0nh \u0111\u1ed9ng cu\u1ed1i c\u00f9ng\n\/\/ Output:\n\/\/ ALICE\n\/\/ ANNA<\/code><\/pre>\n\n\n\n<p>Stream API cung c\u1ea5p v\u00f4 s\u1ed1 c\u00e1c thao t\u00e1c nh\u01b0 <code>filter<\/code>, <code>map<\/code>, <code>reduce<\/code>, <code>collect<\/code>&#8230; gi\u00fap vi\u1ebft m\u00e3 ng\u1eafn g\u1ecdn, d\u1ec5 \u0111\u1ecdc v\u00e0 d\u1ec5 song song h\u00f3a h\u01a1n.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-l\u1eddi-khuyen-d\u1ec3-s\u1eed-d\u1ee5ng-java-collection-framework-hi\u1ec7u-qu\u1ea3\"><span class=\"ez-toc-section\" id=\"Loi_khuyen_de_su_dung_Java_collection_framework_hieu_qua\"><\/span><strong>L\u1eddi khuy\u00ean \u0111\u1ec3 s\u1eed d\u1ee5ng Java collection framework hi\u1ec7u qu\u1ea3<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Vi\u1ec7c s\u1eed d\u1ee5ng th\u00e0nh th\u1ea1o Java Collection Framework kh\u00f4ng ch\u1ec9 d\u1eebng l\u1ea1i \u1edf vi\u1ec7c bi\u1ebft c\u00f3 nh\u1eefng collection n\u00e0o. \u0110\u1ec3 vi\u1ebft m\u00e3 ngu\u1ed3n chuy\u00ean nghi\u1ec7p, d\u1ec5 b\u1ea3o tr\u00ec v\u00e0 hi\u1ec7u qu\u1ea3, b\u1ea1n n\u00ean tu\u00e2n th\u1ee7 c\u00e1c nguy\u00ean t\u1eafc v\u00e0 th\u1ef1c h\u00e0nh t\u1ed1t nh\u1ea5t d\u01b0\u1edbi \u0111\u00e2y.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-l\u1eadp-trinh-h\u01b0\u1edbng-v\u1ec1-interface\"><strong>L\u1eadp tr\u00ecnh h\u01b0\u1edbng v\u1ec1 Interface<\/strong><\/h3>\n\n\n\n<p>\u0110\u00e2y l\u00e0 m\u1ed9t trong nh\u1eefng nguy\u00ean t\u1eafc quan tr\u1ecdng nh\u1ea5t trong l\u1eadp tr\u00ecnh h\u01b0\u1edbng \u0111\u1ed1i t\u01b0\u1ee3ng v\u00e0 \u0111\u1eb7c bi\u1ec7t h\u1eefu \u00edch v\u1edbi Collection Framework.<\/p>\n\n\n\n<p><strong>Nguy\u00ean t\u1eafc:<\/strong> Lu\u00f4n khai b\u00e1o bi\u1ebfn b\u1eb1ng ki\u1ec3u <strong>Interface<\/strong> thay v\u00ec ki\u1ec3u Class c\u1ee5 th\u1ec3.<\/p>\n\n\n\n<p>Thay v\u00ec vi\u1ebft: <code>ArrayList&lt;String&gt; names = new ArrayList&lt;&gt;();<\/code>&nbsp;<\/p>\n\n\n\n<p>H\u00e3y vi\u1ebft: <code>List&lt;String&gt; names = new ArrayList&lt;&gt;();&nbsp;<\/code><\/p>\n\n\n\n<p>C\u00e1ch l\u00e0m n\u00e0y gi\u00fap m\u00e3 ngu\u1ed3n c\u1ee7a b\u1ea1n tr\u1edf n\u00ean <strong>linh ho\u1ea1t h\u01a1n<\/strong>. N\u1ebfu trong t\u01b0\u01a1ng lai, b\u1ea1n nh\u1eadn ra LinkedList ph\u00f9 h\u1ee3p h\u01a1n cho b\u00e0i to\u00e1n c\u1ee7a m\u00ecnh v\u00ec c\u1ea7n th\u00eam\/x\u00f3a nhi\u1ec1u, b\u1ea1n ch\u1ec9 c\u1ea7n thay \u0111\u1ed5i m\u1ed9t ch\u1ed7 duy nh\u1ea5t:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>List&lt;String&gt; names = new LinkedList&lt;&gt;();<\/p>\n<\/blockquote>\n\n\n\n<p>To\u00e0n b\u1ed9 ph\u1ea7n code c\u00f2n l\u1ea1i s\u1eed d\u1ee5ng bi\u1ebfn <code>names<\/code> s\u1ebd kh\u00f4ng c\u1ea7n ph\u1ea3i thay \u0111\u1ed5i, v\u00ec ch\u00fang \u0111\u1ec1u \u0111ang ho\u1ea1t \u0111\u1ed9ng d\u1ef1a tr\u00ean c\u00e1c ph\u01b0\u01a1ng th\u1ee9c \u0111\u01b0\u1ee3c \u0111\u1ecbnh ngh\u0129a trong <code>List<\/code> interface.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-luon-s\u1eed-d\u1ee5ng-generics-lt-gt\"><strong>Lu\u00f4n s\u1eed d\u1ee5ng Generics (<\/strong><strong>&lt;&gt;<\/strong><strong>)<\/strong><\/h3>\n\n\n\n<p>Generics l\u00e0 m\u1ed9t t\u00ednh n\u0103ng c\u1ef1c k\u1ef3 m\u1ea1nh m\u1ebd \u0111\u01b0\u1ee3c gi\u1edbi thi\u1ec7u t\u1eeb Java 5 \u0111\u1ec3 \u0111\u1ea3m b\u1ea3o <strong>an to\u00e0n ki\u1ec3u d\u1eef li\u1ec7u (type safety)<\/strong>.<\/p>\n\n\n\n<p><strong>L\u1ee3i \u00edch:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Ph\u00e1t hi\u1ec7n l\u1ed7i \u1edf th\u1eddi \u0111i\u1ec3m bi\u00ean d\u1ecbch (compile-time):<\/strong> Generics ng\u0103n b\u1ea1n th\u00eam sai ki\u1ec3u d\u1eef li\u1ec7u v\u00e0o m\u1ed9t collection ngay khi vi\u1ebft m\u00e3, thay v\u00ec \u0111\u1ec3 ch\u01b0\u01a1ng tr\u00ecnh ch\u1ea1y r\u1ed3i ph\u00e1t sinh l\u1ed7i <code>ClassCastException<\/code>.<\/li>\n\n\n\n<li><strong>Kh\u00f4ng c\u1ea7n \u00e9p ki\u1ec3u th\u1ee7 c\u00f4ng:<\/strong> B\u1ea1n kh\u00f4ng c\u1ea7n ph\u1ea3i \u00e9p ki\u1ec3u m\u1ed9t c\u00e1ch t\u01b0\u1eddng minh khi l\u1ea5y ph\u1ea7n t\u1eed ra kh\u1ecfi collection, gi\u00fap m\u00e3 ngu\u1ed3n s\u1ea1ch s\u1ebd v\u00e0 an to\u00e0n h\u01a1n.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Kh\u00f4ng d\u00f9ng Generics (kh\u00f4ng n\u00ean)\nList names = new ArrayList();\nnames.add(\"Alice\");\nnames.add(123); \/\/ L\u1ed7i logic nh\u01b0ng ch\u01b0\u01a1ng tr\u00ecnh v\u1eabn bi\u00ean d\u1ecbch\nString name = (String) names.get(1); \/\/ L\u1ed7i ClassCastException khi ch\u1ea1y\n\n\/\/ C\u00f3 d\u00f9ng Generics (n\u00ean d\u00f9ng)\nList&lt;String&gt; safeNames = new ArrayList&lt;&gt;();\nsafeNames.add(\"Alice\");\n\/\/ safeNames.add(123); \/\/ L\u1ed7i ngay t\u1ea1i l\u00fac bi\u00ean d\u1ecbch!\nString safeName = safeNames.get(0); \/\/ Kh\u00f4ng c\u1ea7n \u00e9p ki\u1ec3u<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-nbsp-ch\u1ecdn-dung-collection-cho-dung-cong-vi\u1ec7c\"><strong>&nbsp;Ch\u1ecdn \u0110\u00fang Collection Cho \u0110\u00fang C\u00f4ng Vi\u1ec7c<\/strong><\/h3>\n\n\n\n<p>Vi\u1ec7c l\u1ef1a ch\u1ecdn sai c\u1ea5u tr\u00fac d\u1eef li\u1ec7u c\u00f3 th\u1ec3 khi\u1ebfn hi\u1ec7u n\u0103ng c\u1ee7a \u1ee9ng d\u1ee5ng gi\u1ea3m s\u00fat nghi\u00eam tr\u1ecdng. H\u00e3y lu\u00f4n t\u1ef1 h\u1ecfi: &#8220;M\u00ecnh c\u1ea7n l\u00e0m g\u00ec v\u1edbi d\u1eef li\u1ec7u n\u00e0y?&#8221;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>C\u1ea7n truy c\u1eadp ng\u1eabu nhi\u00ean qua index th\u01b0\u1eddng xuy\u00ean? D\u00f9ng <code>ArrayList<\/code>.<\/li>\n\n\n\n<li>C\u1ea7n th\u00eam\/x\u00f3a ph\u1ea7n t\u1eed \u1edf \u0111\u1ea7u\/cu\u1ed1i\/gi\u1eefa danh s\u00e1ch li\u00ean t\u1ee5c? D\u00f9ng <code>LinkedList<\/code>.<\/li>\n\n\n\n<li>C\u1ea7n \u0111\u1ea3m b\u1ea3o c\u00e1c ph\u1ea7n t\u1eed l\u00e0 duy nh\u1ea5t v\u00e0 kh\u00f4ng quan t\u00e2m th\u1ee9 t\u1ef1? D\u00f9ng <code>HashSet<\/code> \u0111\u1ec3 c\u00f3 hi\u1ec7u n\u0103ng cao nh\u1ea5t.<\/li>\n\n\n\n<li>C\u1ea7n l\u01b0u tr\u1eef c\u00e1c c\u1eb7p key-value \u0111\u1ec3 tra c\u1ee9u nhanh?&nbsp; D\u00f9ng <code>HashMap<\/code>.<\/li>\n\n\n\n<li>C\u1ea7n d\u1eef li\u1ec7u lu\u00f4n \u0111\u01b0\u1ee3c s\u1eafp x\u1ebfp? D\u00f9ng <code>TreeSet<\/code> ho\u1eb7c <code>TreeMap<\/code>.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-hi\u1ec3u-ro-v\u1ec1-equals-va-hashcode\"><strong>Hi\u1ec3u r\u00f5 v\u1ec1 <\/strong><strong>equals()<\/strong><strong> v\u00e0 <\/strong><strong>hashCode()<\/strong><\/h3>\n\n\n\n<p>\u0110\u00e2y l\u00e0 m\u1ed9t \u0111i\u1ec3m c\u1ef1c k\u1ef3 quan tr\u1ecdng nh\u01b0ng th\u01b0\u1eddng b\u1ecb b\u1ecf qua, \u0111\u1eb7c bi\u1ec7t khi b\u1ea1n l\u00e0m vi\u1ec7c v\u1edbi c\u00e1c collection d\u1ef1a tr\u00ean c\u01a1 ch\u1ebf b\u0103m nh\u01b0 <strong>HashSet<\/strong> v\u00e0 <strong>HashMap<\/strong>.<\/p>\n\n\n\n<p>C\u00e1c collection n\u00e0y s\u1eed d\u1ee5ng <code>hashCode()<\/code> \u0111\u1ec3 x\u00e1c \u0111\u1ecbnh &#8220;x\u00f4&#8221; (bucket) n\u01a1i m\u1ed9t \u0111\u1ed1i t\u01b0\u1ee3ng s\u1ebd \u0111\u01b0\u1ee3c l\u01b0u tr\u1eef \u0111\u1ec3 t\u00ecm ki\u1ebfm nhanh. Sau \u0111\u00f3, ch\u00fang d\u00f9ng <code>equals()<\/code> \u0111\u1ec3 so s\u00e1nh v\u00e0 x\u00e1c nh\u1eadn \u0111\u1ed1i t\u01b0\u1ee3ng \u0111\u00f3 c\u00f3 th\u1ef1c s\u1ef1 t\u1ed3n t\u1ea1i trong &#8220;x\u00f4&#8221; hay kh\u00f4ng.<\/p>\n\n\n\n<p><strong>Quy t\u1eafc v\u00e0ng (The Contract):<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>N\u1ebfu hai \u0111\u1ed1i t\u01b0\u1ee3ng b\u1eb1ng nhau theo ph\u01b0\u01a1ng th\u1ee9c <code>equals()<\/code>, ch\u00fang <strong>b\u1eaft bu\u1ed9c<\/strong> ph\u1ea3i c\u00f3 c\u00f9ng m\u1ed9t gi\u00e1 tr\u1ecb <code>hashCode()<\/code>.<\/li>\n\n\n\n<li>N\u1ebfu hai \u0111\u1ed1i t\u01b0\u1ee3ng c\u00f3 c\u00f9ng <code>hashCode()<\/code>, ch\u00fang <strong>kh\u00f4ng nh\u1ea5t thi\u1ebft<\/strong> ph\u1ea3i b\u1eb1ng nhau theo <code>equals()<\/code>.<\/li>\n<\/ol>\n\n\n\n<p>N\u1ebfu b\u1ea1n override <code>equals()<\/code> m\u00e0 kh\u00f4ng override <code>hashCode()<\/code> cho c\u00e1c \u0111\u1ed1i t\u01b0\u1ee3ng c\u1ee7a m\u00ecnh, <code>HashSet<\/code> v\u00e0 <code>HashMap<\/code> s\u1ebd ho\u1ea1t \u0111\u1ed9ng sai, d\u1eabn \u0111\u1ebfn vi\u1ec7c kh\u00f4ng t\u00ecm th\u1ea5y \u0111\u1ed1i t\u01b0\u1ee3ng d\u00f9 n\u00f3 \u0111\u00e3 c\u00f3 trong collection ho\u1eb7c l\u01b0u tr\u1eef c\u00e1c \u0111\u1ed1i t\u01b0\u1ee3ng tr\u00f9ng l\u1eb7p.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-cac-cau-h\u1ecfi-th\u01b0\u1eddng-g\u1eb7p\"><span class=\"ez-toc-section\" id=\"Cac_cau_hoi_thuong_gap\"><\/span><strong>C\u00e1c c\u00e2u h\u1ecfi th\u01b0\u1eddng g\u1eb7p<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-arraylist-va-vector-khac-nhau-\u1edf-di\u1ec3m-nao\"><strong>ArrayList<\/strong><strong> v\u00e0 <\/strong><strong>Vector<\/strong><strong> kh\u00e1c nhau \u1edf \u0111i\u1ec3m n\u00e0o?<\/strong><\/h3>\n\n\n\n<p>\u0110i\u1ec3m kh\u00e1c bi\u1ec7t ch\u00ednh n\u1eb1m \u1edf <strong>t\u00ednh \u0111\u1ed3ng b\u1ed9 (synchronization)<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>Vector<\/code>: L\u00e0 m\u1ed9t l\u1edbp c\u0169 (legacy class), t\u1ea5t c\u1ea3 c\u00e1c ph\u01b0\u01a1ng th\u1ee9c c\u1ee7a n\u00f3 \u0111\u1ec1u \u0111\u01b0\u1ee3c synchronized. \u0110i\u1ec1u n\u00e0y c\u00f3 ngh\u0129a l\u00e0 <code>Vector<\/code> an to\u00e0n cho lu\u1ed3ng (thread-safe), nhi\u1ec1u lu\u1ed3ng c\u00f3 th\u1ec3 truy c\u1eadp v\u00e0o n\u00f3 m\u00e0 kh\u00f4ng g\u00e2y ra l\u1ed7i d\u1eef li\u1ec7u. Tuy nhi\u00ean, ch\u00ednh v\u00ec c\u01a1 ch\u1ebf n\u00e0y m\u00e0 hi\u1ec7u n\u0103ng c\u1ee7a n\u00f3 s\u1ebd ch\u1eadm h\u01a1n.<\/li>\n\n\n\n<li><code>ArrayList<\/code>: Kh\u00f4ng \u0111\u01b0\u1ee3c \u0111\u1ed3ng b\u1ed9 h\u00f3a, v\u00ec v\u1eady n\u00f3 kh\u00f4ng an to\u00e0n cho lu\u1ed3ng. \u0110\u1ed5i l\u1ea1i, <code>ArrayList<\/code> c\u00f3 hi\u1ec7u n\u0103ng cao h\u01a1n trong m\u00f4i tr\u01b0\u1eddng \u0111\u01a1n lu\u1ed3ng.<\/li>\n<\/ul>\n\n\n\n<p><strong>L\u1eddi khuy\u00ean:<\/strong> Trong h\u1ea7u h\u1ebft c\u00e1c tr\u01b0\u1eddng h\u1ee3p, h\u00e3y \u01b0u ti\u00ean s\u1eed d\u1ee5ng <code>ArrayList<\/code>. N\u1ebfu b\u1ea1n c\u1ea7n m\u1ed9t danh s\u00e1ch an to\u00e0n cho lu\u1ed3ng, h\u00e3y s\u1eed d\u1ee5ng <code>Collections.synchronizedList(new ArrayList&lt;&gt;())<\/code> ho\u1eb7c c\u00e1c c<code>ollection<\/code> trong package <code>java.util.concurrent<\/code> nh\u01b0 <code>CopyOnWriteArrayList<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-hashmap-va-hashtable-khac-nhau-nh\u01b0-th\u1ebf-nao\"><strong>HashMap<\/strong><strong> v\u00e0 <\/strong><strong>Hashtable<\/strong><strong> kh\u00e1c nhau nh\u01b0 th\u1ebf n\u00e0o?<\/strong><\/h3>\n\n\n\n<p>Gi\u1ed1ng nh\u01b0 c\u1eb7p <code>ArrayList<\/code>\/<code>Vector<\/code>, s\u1ef1 kh\u00e1c bi\u1ec7t ch\u00ednh c\u0169ng n\u1eb1m \u1edf t\u00ednh \u0111\u1ed3ng b\u1ed9 v\u00e0 m\u1ed9t v\u00e0i \u0111i\u1ec3m kh\u00e1c:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>Hashtable<\/code>: L\u00e0 m\u1ed9t l\u1edbp c\u0169, \u0111\u01b0\u1ee3c \u0111\u1ed3ng b\u1ed9 h\u00f3a (thread-safe) v\u00e0 hi\u1ec7u n\u0103ng ch\u1eadm h\u01a1n. Quan tr\u1ecdng l\u00e0, <code>Hashtable<\/code> kh\u00f4ng cho ph\u00e9p b\u1ea5t k\u1ef3 <code>key<\/code> hay <code>value<\/code> n\u00e0o l\u00e0 <code>null<\/code>.<\/li>\n\n\n\n<li><code>HashMap<\/code>: Kh\u00f4ng \u0111\u01b0\u1ee3c \u0111\u1ed3ng b\u1ed9 h\u00f3a v\u00e0 c\u00f3 hi\u1ec7u n\u0103ng cao h\u01a1n. <code>HashMap<\/code> cho ph\u00e9p m\u1ed9t key l\u00e0 <code>null<\/code> v\u00e0 nhi\u1ec1u <code>value<\/code> l\u00e0 <code>null<\/code>.<\/li>\n<\/ul>\n\n\n\n<p><strong>L\u1eddi khuy\u00ean:<\/strong> H\u00e3y lu\u00f4n \u01b0u ti\u00ean <code>HashMap<\/code>. N\u1ebfu c\u1ea7n m\u1ed9t <code>Map<\/code> an to\u00e0n cho lu\u1ed3ng, h\u00e3y s\u1eed d\u1ee5ng <code>Collections.synchronizedMap(new HashMap&lt;&gt;())<\/code> ho\u1eb7c <code>ConcurrentHashMap<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-t\u1ea1i-sao-map-khong-k\u1ebf-th\u1eeba-extends-collection\"><strong>T\u1ea1i sao <\/strong><strong>Map<\/strong><strong> kh\u00f4ng k\u1ebf th\u1eeba (extends) <\/strong><strong>Collection<\/strong><strong>?<\/strong><\/h3>\n\n\n\n<p>\u0110\u00e2y l\u00e0 m\u1ed9t c\u00e2u h\u1ecfi v\u1ec1 m\u1eb7t thi\u1ebft k\u1ebf c\u1ee7a framework. M\u1eb7c d\u00f9 <code>Map<\/code> c\u0169ng l\u00e0 m\u1ed9t c\u1ea5u tr\u00fac d\u1eef li\u1ec7u \u0111\u1ec3 ch\u1ee9a c\u00e1c \u0111\u1ed1i t\u01b0\u1ee3ng, nh\u01b0ng tri\u1ebft l\u00fd c\u1ee7a n\u00f3 kh\u00e1c bi\u1ec7t c\u01a1 b\u1ea3n so v\u1edbi <code>Collection<\/code>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Collection<\/strong>: \u0110\u1ea1i di\u1ec7n cho m\u1ed9t t\u1eadp h\u1ee3p c\u00e1c ph\u1ea7n t\u1eed \u0111\u01a1n l\u1ebb. C\u00e1c h\u00e0nh vi c\u1ed1t l\u00f5i c\u1ee7a n\u00f3 xoay quanh vi\u1ec7c th\u00eam, x\u00f3a, ch\u1ee9a m\u1ed9t ph\u1ea7n t\u1eed (<code>add(element)<\/code>, <code>contains(element)<\/code>).<\/li>\n\n\n\n<li>Map: \u0110\u1ea1i di\u1ec7n cho m\u1ed9t t\u1eadp h\u1ee3p c\u00e1c c\u1eb7p key-value. C\u00e1c h\u00e0nh vi c\u1ed1t l\u00f5i c\u1ee7a n\u00f3 xoay quanh <code>key<\/code> nh\u01b0 <code>put(key, value)<\/code>, <code>get(key)<\/code>, <code>containsKey(key)<\/code>.<\/li>\n<\/ul>\n\n\n\n<p>C\u1ea5u tr\u00fac v\u00e0 m\u1ee5c \u0111\u00edch s\u1eed d\u1ee5ng c\u1ee7a ch\u00fang qu\u00e1 kh\u00e1c nhau \u0111\u1ec3 c\u00f3 th\u1ec3 h\u1ee3p nh\u1ea5t v\u00e0o chung m\u1ed9t h\u1ec7 th\u1ed1ng k\u1ebf th\u1eeba. <code>Map<\/code> kh\u00f4ng ph\u1ea3i l\u00e0 m\u1ed9t &#8220;Collection c\u1ee7a c\u00e1c ph\u1ea7n t\u1eed&#8221;, m\u00e0 l\u00e0 m\u1ed9t c\u1ea5u tr\u00fac \u00e1nh x\u1ea1 ri\u00eang bi\u1ec7t.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-khi-nao-thi-nen-dung-iterator-thay-cho-vong-l\u1eb7p-for-each\"><strong>Khi n\u00e0o th\u00ec n\u00ean d\u00f9ng <\/strong><strong>Iterator<\/strong><strong> thay cho v\u00f2ng l\u1eb7p for-each?<\/strong><\/h3>\n\n\n\n<p>H\u00e3y d\u00f9ng <code>Iterator<\/code> khi b\u1ea1n c\u00f3 nhu c\u1ea7u <strong>x\u00f3a ph\u1ea7n t\u1eed kh\u1ecfi collection ngay trong l\u00fac \u0111ang duy\u1ec7t qua n\u00f3<\/strong>.<\/p>\n\n\n\n<p>V\u00f2ng l\u1eb7p <code>for-each<\/code> r\u1ea5t ti\u1ec7n l\u1ee3i v\u00e0 d\u1ec5 \u0111\u1ecdc, nh\u01b0ng n\u1ebfu b\u1ea1n c\u1ed1 g\u1eafng g\u1ecdi ph\u01b0\u01a1ng th\u1ee9c <code>collection.remove()<\/code> b\u00ean trong n\u00f3, ch\u01b0\u01a1ng tr\u00ecnh s\u1ebd n\u00e9m ra m\u1ed9t ngo\u1ea1i l\u1ec7 <code>ConcurrentModificationException<\/code>. <code>Iterator<\/code> cung c\u1ea5p ph\u01b0\u01a1ng th\u1ee9c <code>iterator.remove()<\/code> \u0111\u01b0\u1ee3c thi\u1ebft k\u1ebf ri\u00eang \u0111\u1ec3 x\u1eed l\u00fd vi\u1ec7c n\u00e0y m\u1ed9t c\u00e1ch an to\u00e0n.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ D\u00f9ng Iterator \u0111\u1ec3 x\u00f3a ph\u1ea7n t\u1eed m\u1ed9t c\u00e1ch an to\u00e0n\nIterator&lt;String&gt; iterator = myList.iterator();\nwhile (iterator.hasNext()) {\n    String element = iterator.next();\n    if (someCondition) {\n        iterator.remove(); \/\/ \u0110\u00fang v\u00e0 an to\u00e0n!\n    }\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-k\u1ebft-lu\u1eadn\"><span class=\"ez-toc-section\" id=\"Ket_luan\"><\/span><strong>K\u1ebft lu\u1eadn<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Java Collection Framework l\u00e0 m\u1ed9t ph\u1ea7n kh\u00f4ng th\u1ec3 thi\u1ebfu v\u00e0 v\u00f4 c\u00f9ng m\u1ea1nh m\u1ebd c\u1ee7a ng\u00f4n ng\u1eef Java. B\u1eb1ng vi\u1ec7c n\u1eafm v\u1eefng c\u1ea5u tr\u00fac t\u1eeb c\u00e1c <strong>Interface<\/strong> c\u1ed1t l\u00f5i, hi\u1ec3u r\u00f5 \u0111\u1eb7c \u0111i\u1ec3m c\u1ee7a t\u1eebng l\u1edbp <strong>tri\u1ec3n khai c\u1ee5 th\u1ec3<\/strong>, v\u00e0 \u00e1p d\u1ee5ng c\u00e1c <strong>th\u1ef1c h\u00e0nh t\u1ed1t nh\u1ea5t<\/strong>, b\u1ea1n c\u00f3 th\u1ec3 vi\u1ebft m\u00e3 ngu\u1ed3n kh\u00f4ng ch\u1ec9 ch\u1ea1y \u0111\u00fang m\u00e0 c\u00f2n hi\u1ec7u qu\u1ea3, r\u00f5 r\u00e0ng v\u00e0 d\u1ec5 b\u1ea3o tr\u00ec.<\/p>\n\n\n\n<p>Hy v\u1ecdng qua b\u00e0i vi\u1ebft n\u00e0y, b\u1ea1n \u0111\u00e3 c\u00f3 m\u1ed9t c\u00e1i nh\u00ecn t\u1ed5ng quan v\u00e0 v\u1eefng ch\u1eafc v\u1ec1 framework quan tr\u1ecdng n\u00e0y. Ch\u00eca kh\u00f3a \u0111\u1ec3 th\u1ef1c s\u1ef1 th\u00e0nh th\u1ea1o ch\u00ednh l\u00e0 th\u1ef1c h\u00e0nh \u2013 h\u00e3y th\u1eed nghi\u1ec7m v\u1edbi c\u00e1c lo\u1ea1i collection kh\u00e1c nhau trong nh\u1eefng d\u1ef1 \u00e1n c\u1ee7a ri\u00eang b\u1ea1n \u0111\u1ec3 c\u1ea3m nh\u1eadn s\u1ef1 kh\u00e1c bi\u1ec7t.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Java Collection Framework (JCF) l\u00e0 m\u1ed9t ki\u1ebfn tr\u00fac n\u1ec1n t\u1ea3ng trong Java, cung c\u1ea5p c\u00e1c l\u1edbp v\u00e0 giao di\u1ec7n \u0111\u01b0\u1ee3c thi\u1ebft k\u1ebf s\u1eb5n \u0111\u1ec3 l\u01b0u tr\u1eef v\u00e0 thao t\u00e1c hi\u1ec7u qu\u1ea3 tr\u00ean c\u00e1c nh\u00f3m \u0111\u1ed1i t\u01b0\u1ee3ng. \u0110i\u1ec3m m\u1ea1nh c\u1ee7a JCF n\u1eb1m \u1edf vi\u1ec7c gi\u00fap l\u1eadp tr\u00ecnh vi\u00ean ti\u1ebft ki\u1ec7m th\u1eddi gian v\u00e0 c\u00f4ng s\u1ee9c: thay [&hellip;]<\/p>\n","protected":false},"author":203,"featured_media":93366,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_gspb_post_css":"","footnotes":""},"categories":[109,10350],"tags":[],"class_list":["post-92791","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-chuyen-mon-it","category-java"],"blocksy_meta":[],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.8 (Yoast SEO v27.8) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Java Collection Framework: Chi ti\u1ebft c\u1ea5u tr\u00fac v\u00e0 c\u00e1c best practice - ITviec Blog<\/title>\n<meta name=\"description\" content=\"T\u00ecm hi\u1ec3u chi ti\u1ebft Java Collection Framework t\u1eeb c\u00e1c interfaces c\u1ed1t l\u00f5i, s\u01a1 \u0111\u1ed3 ph\u00e2n c\u1ea5p, cho \u0111\u1ebfn c\u00e1c best practices khi th\u1ef1c h\u00e0nh v\u1edbi JCF.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/itviec.com\/blog\/java-collection-framework-la-gi\/\" \/>\n<meta property=\"og:locale\" content=\"vi_VN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java Collection Framework: Chi ti\u1ebft c\u1ea5u tr\u00fac v\u00e0 c\u00e1c best practice\" \/>\n<meta property=\"og:description\" content=\"Java Collection Framework (JCF) l\u00e0 m\u1ed9t ki\u1ebfn tr\u00fac n\u1ec1n t\u1ea3ng trong Java, cung c\u1ea5p c\u00e1c l\u1edbp v\u00e0 giao di\u1ec7n \u0111\u01b0\u1ee3c thi\u1ebft k\u1ebf s\u1eb5n \u0111\u1ec3 l\u01b0u tr\u1eef v\u00e0 thao t\u00e1c hi\u1ec7u qu\u1ea3 tr\u00ean\" \/>\n<meta property=\"og:url\" content=\"https:\/\/itviec.com\/blog\/java-collection-framework-la-gi\/\" \/>\n<meta property=\"og:site_name\" content=\"ITviec Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ITviec\" \/>\n<meta property=\"article:published_time\" content=\"2025-11-30T15:18:31+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-11-30T15:18:35+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/11\/Java-Collection-Framework-scaled.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2560\" \/>\n\t<meta property=\"og:image:height\" content=\"1347\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Tien Tran\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@ITviec\" \/>\n<meta name=\"twitter:site\" content=\"@ITviec\" \/>\n<meta name=\"twitter:label1\" content=\"\u0110\u01b0\u1ee3c vi\u1ebft b\u1edfi\" \/>\n\t<meta name=\"twitter:data1\" content=\"Tien Tran\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u01af\u1edbc t\u00ednh th\u1eddi gian \u0111\u1ecdc\" \/>\n\t<meta name=\"twitter:data2\" content=\"21 ph\u00fat\" \/>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Java Collection Framework: Chi ti\u1ebft c\u1ea5u tr\u00fac v\u00e0 c\u00e1c best practice - ITviec Blog","description":"T\u00ecm hi\u1ec3u chi ti\u1ebft Java Collection Framework t\u1eeb c\u00e1c interfaces c\u1ed1t l\u00f5i, s\u01a1 \u0111\u1ed3 ph\u00e2n c\u1ea5p, cho \u0111\u1ebfn c\u00e1c best practices khi th\u1ef1c h\u00e0nh v\u1edbi JCF.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/itviec.com\/blog\/java-collection-framework-la-gi\/","og_locale":"vi_VN","og_type":"article","og_title":"Java Collection Framework: Chi ti\u1ebft c\u1ea5u tr\u00fac v\u00e0 c\u00e1c best practice","og_description":"Java Collection Framework (JCF) l\u00e0 m\u1ed9t ki\u1ebfn tr\u00fac n\u1ec1n t\u1ea3ng trong Java, cung c\u1ea5p c\u00e1c l\u1edbp v\u00e0 giao di\u1ec7n \u0111\u01b0\u1ee3c thi\u1ebft k\u1ebf s\u1eb5n \u0111\u1ec3 l\u01b0u tr\u1eef v\u00e0 thao t\u00e1c hi\u1ec7u qu\u1ea3 tr\u00ean","og_url":"https:\/\/itviec.com\/blog\/java-collection-framework-la-gi\/","og_site_name":"ITviec Blog","article_publisher":"https:\/\/www.facebook.com\/ITviec","article_published_time":"2025-11-30T15:18:31+00:00","article_modified_time":"2025-11-30T15:18:35+00:00","og_image":[{"width":2560,"height":1347,"url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/11\/Java-Collection-Framework-scaled.png","type":"image\/png"}],"author":"Tien Tran","twitter_card":"summary_large_image","twitter_creator":"@ITviec","twitter_site":"@ITviec","twitter_misc":{"\u0110\u01b0\u1ee3c vi\u1ebft b\u1edfi":"Tien Tran","\u01af\u1edbc t\u00ednh th\u1eddi gian \u0111\u1ecdc":"21 ph\u00fat"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/itviec.com\/blog\/java-collection-framework-la-gi\/#article","isPartOf":{"@id":"https:\/\/itviec.com\/blog\/java-collection-framework-la-gi\/"},"author":{"name":"Tien Tran","@id":"https:\/\/itviec.com\/blog\/#\/schema\/person\/1595d671c49cfa2a48cd3c0a047a1298"},"headline":"Java Collection Framework: Chi ti\u1ebft c\u1ea5u tr\u00fac v\u00e0 c\u00e1c best practice","datePublished":"2025-11-30T15:18:31+00:00","dateModified":"2025-11-30T15:18:35+00:00","mainEntityOfPage":{"@id":"https:\/\/itviec.com\/blog\/java-collection-framework-la-gi\/"},"wordCount":5612,"publisher":{"@id":"https:\/\/itviec.com\/blog\/#organization"},"image":{"@id":"https:\/\/itviec.com\/blog\/java-collection-framework-la-gi\/#primaryimage"},"thumbnailUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/11\/Java-Collection-Framework-scaled.png","articleSection":["Chuy\u00ean m\u00f4n IT","Java"],"inLanguage":"vi"},{"@type":"WebPage","@id":"https:\/\/itviec.com\/blog\/java-collection-framework-la-gi\/","url":"https:\/\/itviec.com\/blog\/java-collection-framework-la-gi\/","name":"Java Collection Framework: Chi ti\u1ebft c\u1ea5u tr\u00fac v\u00e0 c\u00e1c best practice - ITviec Blog","isPartOf":{"@id":"https:\/\/itviec.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/itviec.com\/blog\/java-collection-framework-la-gi\/#primaryimage"},"image":{"@id":"https:\/\/itviec.com\/blog\/java-collection-framework-la-gi\/#primaryimage"},"thumbnailUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/11\/Java-Collection-Framework-scaled.png","datePublished":"2025-11-30T15:18:31+00:00","dateModified":"2025-11-30T15:18:35+00:00","description":"T\u00ecm hi\u1ec3u chi ti\u1ebft Java Collection Framework t\u1eeb c\u00e1c interfaces c\u1ed1t l\u00f5i, s\u01a1 \u0111\u1ed3 ph\u00e2n c\u1ea5p, cho \u0111\u1ebfn c\u00e1c best practices khi th\u1ef1c h\u00e0nh v\u1edbi JCF.","breadcrumb":{"@id":"https:\/\/itviec.com\/blog\/java-collection-framework-la-gi\/#breadcrumb"},"inLanguage":"vi","potentialAction":[{"@type":"ReadAction","target":["https:\/\/itviec.com\/blog\/java-collection-framework-la-gi\/"]}]},{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/itviec.com\/blog\/java-collection-framework-la-gi\/#primaryimage","url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/11\/Java-Collection-Framework-scaled.png","contentUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/11\/Java-Collection-Framework-scaled.png","width":800,"height":421,"caption":"Java Collection Framework - itviec blog"},{"@type":"BreadcrumbList","@id":"https:\/\/itviec.com\/blog\/java-collection-framework-la-gi\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Chuy\u00ean m\u00f4n IT","item":"https:\/\/itviec.com\/blog\/chuyen-mon-it\/"},{"@type":"ListItem","position":2,"name":"Java Collection Framework: Chi ti\u1ebft c\u1ea5u tr\u00fac v\u00e0 c\u00e1c best practice"}]},{"@type":"WebSite","@id":"https:\/\/itviec.com\/blog\/#website","url":"https:\/\/itviec.com\/blog\/","name":"ITviec Blog","description":"IT Jobs &amp; People in Vietnam","publisher":{"@id":"https:\/\/itviec.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/itviec.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"vi"},{"@type":"Organization","@id":"https:\/\/itviec.com\/blog\/#organization","name":"ITviec","url":"https:\/\/itviec.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/itviec.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2018\/12\/itviec-black-square-facebook.png","contentUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2018\/12\/itviec-black-square-facebook.png","width":1800,"height":1800,"caption":"ITviec"},"image":{"@id":"https:\/\/itviec.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/ITviec","https:\/\/x.com\/ITviec","https:\/\/www.linkedin.com\/company\/itviec","https:\/\/www.youtube.com\/channel\/UCYthAQ3bcGr57M_ag5gHDvQ"]},{"@type":"Person","@id":"https:\/\/itviec.com\/blog\/#\/schema\/person\/1595d671c49cfa2a48cd3c0a047a1298","name":"Tien Tran","image":{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/05\/tien-tran-author-e1715658627643-100x100.jpg","url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/05\/tien-tran-author-e1715658627643-100x100.jpg","contentUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/05\/tien-tran-author-e1715658627643-100x100.jpg","caption":"Tien Tran"},"url":"https:\/\/itviec.com\/blog\/author\/tien-tran\/"}]}},"_links":{"self":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts\/92791","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/users\/203"}],"replies":[{"embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/comments?post=92791"}],"version-history":[{"count":2,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts\/92791\/revisions"}],"predecessor-version":[{"id":93367,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts\/92791\/revisions\/93367"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/media\/93366"}],"wp:attachment":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/media?parent=92791"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/categories?post=92791"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/tags?post=92791"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}