\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{nafanya} \pdfinfo{ /Title (java-coding-interview-cheat-sheet.pdf) /Creator (Cheatography) /Author (nafanya) /Subject (Java Coding Interview Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{7D1F10} \definecolor{LightBackground}{HTML}{FAF8F7} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{Java Coding Interview Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{nafanya} via \textcolor{DarkBackground}{\uline{cheatography.com/202788/cs/43072/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}nafanya \\ \uline{cheatography.com/nafanya} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 20th April, 2024.\\ Updated 6th September, 2024.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{2} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{String}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Declaration}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{String s = "​​Hello world";} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{String s = {\bf{new}} String("Hello world!​​");} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{String s = {\bf{new}} \seqsplit{String​​(c​h​a​rA​​rray);}} \tn % Row Count 5 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Methods}}} \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{char c = s.{\bf{char​​At​}}(​i​ndex);} \tn % Row Count 7 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{int index = s.{\bf{indexOf}}​("world");} \tn % Row Count 8 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{String subs = s.{\bf{subs​​tr​i​n​g}}(​​sta​rtIdx, endIdx);} \tn % Row Count 10 (+ 2) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{bool hasRed = s.{\bf{cont​​ai​n​s}}​("r​​ed");} \tn % Row Count 12 (+ 2) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{String newStr = s.{\bf{repl​​ac​e}}​('a', 'b');} \tn % Row Count 14 (+ 2) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{String lowerC​​aseStr = s.{\bf{toLo​​we​r​C​ase}}();} \tn % Row Count 16 (+ 2) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{String upperC​​aseStr = s.{\bf{toUp​​pe​r​C​ase}}();} \tn % Row Count 18 (+ 2) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Convert}}} \tn % Row Count 19 (+ 1) % Row 13 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{String s = String.{\bf{va​​lu​e​O​f}}(​​num​​ber);} \tn % Row Count 21 (+ 2) % Row 14 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{String{[} {]} arrayOfStr = s.{\bf{spli​​t}}(​"​,​");} \tn % Row Count 23 (+ 2) % Row 15 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{char{[} {]} charArray = s.{\bf{toCh​​ar​A​r​ray}}();} \tn % Row Count 25 (+ 2) % Row 16 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{int number = Intege​​r.{\bf{p​​a​rs​​eIn​​t}}(​"​1​2​3");} \tn % Row Count 27 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{ArrayList}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Declaration}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{ArrayList\textless{}String\textgreater{} cars = {\bf{new}} ArrayList\textless{}\textgreater{}();} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{ArrayList\textless{}Integer\textgreater{} nums= {\bf{new}} ArrayList\textless{}\textgreater{}(Arrays.asList(1, 2));} \tn % Row Count 4 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{{\bf{Methods}}} \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{cars.{\bf{add}}("Volvo");} \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{cars.{\bf{get}}(0);} \tn % Row Count 7 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{cars.{\bf{set}}(0, "Opel");} \tn % Row Count 8 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{cars.{\bf{remove}}(0);} \tn % Row Count 9 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{cars.{\bf{clear}}(); //remove all} \tn % Row Count 10 (+ 1) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{cars.{\bf{size}}();} \tn % Row Count 11 (+ 1) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{int firstIndex = cars.{\bf{indexOf}}("Volvo");} \tn % Row Count 12 (+ 1) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{{\bf{Sort \& Iterate}}} \tn % Row Count 13 (+ 1) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Collections.{\bf{sort}}(cars);} \tn % Row Count 14 (+ 1) % Row 13 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Collections.{\bf{reverse}}(cars);} \tn % Row Count 15 (+ 1) % Row 14 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{for ( int i = 0; i \textless{} cars.size(); i++ ) \{ \}} \tn % Row Count 16 (+ 1) % Row 15 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{for ( String car : cars ) \{ \}} \tn % Row Count 17 (+ 1) % Row 16 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Iterator it = cars.iterator();\{\{nl\}\} while ( it.hasNext() ) \{ it.next(); \};} \tn % Row Count 19 (+ 2) % Row 17 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{{\bf{Convert to array}}} \tn % Row Count 20 (+ 1) % Row 18 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Integer{[}{]} arr = {\bf{new}} Integer{[}{\emph{arrayList}}.size(){]};} \tn % Row Count 22 (+ 2) % Row 19 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{arr = {\emph{arrayList}}.{\bf{toArray}}(arr);} \tn % Row Count 23 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Array}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Declaration}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{int{[} {]} array= \{1, 2, 3, 4, 5, 6\};} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{int{[} {]} array = {\bf{new}} int{[}10{]};} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{int{[} {]}{[} {]} twoDArray = {\bf{new}} int{[}n{]}{[}m{]};} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Methods}}} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{int n = array.length;} \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Sort \& Iterate}}} \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Arrays.sort(array);} \tn % Row Count 8 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Arrays.sort(array, (a,b) -\textgreater{} Integer.compare(a,b))} \tn % Row Count 9 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Character}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Declaration \& Methods}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{char myGrade = 'B';} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{(char) (1 + 'a') -\textgreater{} 'b'} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{{\bf{Convert to other types}}} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{int a = ch - '0';} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{char myVar1 = 65; // myVar1 = 'A'} \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{} \tn % Row Count 6 (+ 0) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Character c1 = {\bf{new}} Character('r');} \tn % Row Count 7 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{String s1 = c1.toString();} \tn % Row Count 8 (+ 1) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{String s2 = String.{\bf{valueOf}}(c1);} \tn % Row Count 9 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{LinkedList}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Declaration}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{LinkedList\textless{}String\textgreater{} cars = {\bf{new}} LinkedList\textless{}String\textgreater{}();} \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Method}}} \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{cars.{\bf{add}}("Volvo");} \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{cars.{\bf{addFirst}}("Mazda");} \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{cars.{\bf{addLast}}("Ford");} \tn % Row Count 7 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{cars.{\bf{removeFirst}}();} \tn % Row Count 8 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{cars.{\bf{removeLast}}();} \tn % Row Count 9 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{cars.{\bf{getFirst}}();} \tn % Row Count 10 (+ 1) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{cars.{\bf{getLast}}();} \tn % Row Count 11 (+ 1) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{cars.{\bf{size}}();} \tn % Row Count 12 (+ 1) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{{\bf{Iterate}}} \tn % Row Count 13 (+ 1) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{for ( int i = 0; i \textless{} cars.size(); i++ ) \{ \}} \tn % Row Count 14 (+ 1) % Row 13 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{for ( String car: cars ) \{ \}} \tn % Row Count 15 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{HashMap}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Declaration}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{HashMap\textless{}String, Integer\textgreater{} map = {\bf{new}} HashMap\textless{}\textgreater{}();} \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Methods}}} \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{map.{\bf{put}}("key1", 10);} \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{map.{\bf{containsKey}}("key2")} \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{map.{\bf{containsValue}}(2));} \tn % Row Count 7 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{map.{\bf{get}}("key1");} \tn % Row Count 8 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{map.{\bf{getOrDefault}}("key1", 0);} \tn % Row Count 9 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{map.{\bf{remove}}("key1");} \tn % Row Count 10 (+ 1) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{map.{\bf{clear}}(); //remove all items} \tn % Row Count 11 (+ 1) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{map.{\bf{put}}("key1", 5); //update key1} \tn % Row Count 12 (+ 1) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{map.{\bf{size}}();} \tn % Row Count 13 (+ 1) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Iterate}}} \tn % Row Count 14 (+ 1) % Row 13 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{for ( String key : map.keySet() ) \{ \}} \tn % Row Count 15 (+ 1) % Row 14 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{for ( Integer i : map.values() ) \{ \}} \tn % Row Count 16 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Queue (LinkedList implementation)}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Declaration}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Queue\textless{}String\textgreater{} queue = {\bf{new}} LinkedList\textless{}\textgreater{}();} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Methods}}} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{queue.{\bf{add}}("apple");} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{queue.{\bf{remove}}(); // remove first element} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{queue.{\bf{peek}}(); //show first element} \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{queue.{\bf{size}}();} \tn % Row Count 7 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{LinkedList vs PriorityQueue}} \tn \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{LinkedList preserves the insertion order, PriorityQueue does not. The elements of the priority queue are ordered according to their natural ordering, or by a Comparator provided at queue construction time.% Row Count 5 (+ 5) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Stack}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Declaration}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Stack\textless{}Integer\textgreater{} stack = {\bf{new}} Stack\textless{}Integer\textgreater{}();} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{stack.{\bf{push}}(1);} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{stack.{\bf{peek}}();} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{stack.{\bf{pop}}();} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{stack.{\bf{isEmpty}}()} \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{int index = stack.{\bf{search}}(2);} \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{{\bf{Iterate}}} \tn % Row Count 8 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{for ( Integer item : stack ) \{ \}} \tn % Row Count 9 (+ 1) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Iterator it = stack.iterator();\{\{nl\}\} while ( it.hasNext() ) \{ it.next(); \};} \tn % Row Count 11 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{HashSet}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Declaration}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{HashSet\textless{}String\textgreater{} cars = {\bf{new}} HashSet\textless{}String\textgreater{}();} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Methods}}} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{cars.{\bf{add}}("Volvo");} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{cars.{\bf{contains}}("Mazda");} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{cars.{\bf{remove}}("Volvo");} \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{cars.{\bf{clear}}();} \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{cars.{\bf{size}}();} \tn % Row Count 8 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Iterate \& Convert}}} \tn % Row Count 9 (+ 1) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{for ( String car : cars ) \{ \}} \tn % Row Count 10 (+ 1) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Iterator\textless{}Integer\textgreater{} it = cars.iterator();\{\{nl\}\} while ( it.hasNext() ) \{ it.next();\};} \tn % Row Count 12 (+ 2) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{String{[}{]} array = cars.{\bf{toArray}}(} \tn % Row Count 13 (+ 1) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\{\{ar\}\}{\bf{new}} String{[}cars.{\bf{size}}(){]})} \tn % Row Count 14 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Queue (PriorityQueue implementation)}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Declaration}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Queue\textless{}Integer\textgreater{} pQueue = {\bf{new}} PriorityQueue\textless{}Integer\textgreater{}();} \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Methods}}} \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{pQueue.{\bf{add}}(10);} \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{pQueue.{\bf{peek}}(); //return top element} \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{pQueue.{\bf{poll}}(); //return and remove} \tn % Row Count 7 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{pQueue.{\bf{remove}}(2); //remove first 2} \tn % Row Count 8 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{{\bf{Iterate}}} \tn % Row Count 9 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Iterator it = pQueue.iterator();\{\{nl\}\} while ( it.hasNext() ) \{ it.next(); \};} \tn % Row Count 11 (+ 2) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{{\bf{Comparartor}}} \tn % Row Count 12 (+ 1) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\{\{link="https://howtodoinjava.com/java/collections/java-priorityqueue/"\}\}Comparator examples\{\{/link\}\}} \tn % Row Count 15 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.52 cm} x{4.48 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Bitwise Operators}} \tn % Row 0 \SetRowColor{LightBackground} OR & 0101 | 0111 = 0111 \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} AND & 0101 \& 0111 = 0101 \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} XOR & 0101 \textasciicircum{} 0111 = 0010 \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} NOT & \textasciitilde{} 0101 = 1010 \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} Left shift & 000110 \textless{}\textless{} 1 = 001100 \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} Right shift & 10110101 \textgreater{}\textgreater{} 1 = 11011010 \tn % Row Count 7 (+ 2) % Row 6 \SetRowColor{LightBackground} Unsigned Right Shift & 10110101 \textgreater{}\textgreater{}\textgreater{} 1 = 01011010 \tn % Row Count 9 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.12 cm} x{4.88 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Other}} \tn % Row 0 \SetRowColor{LightBackground} Min integer & Integer.MIN\_VALUE \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} Max integer & Integer.MAX\_VALUE \tn % Row Count 2 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}