\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{shravya\_kavali2} \pdfinfo{ /Title (java-cheatsheet.pdf) /Creator (Cheatography) /Author (shravya\_kavali2) /Subject (Java cheatsheet 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}{A32797} \definecolor{LightBackground}{HTML}{F9F1F8} \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 cheatsheet Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{shravya\_kavali2} via \textcolor{DarkBackground}{\uline{cheatography.com/191379/cs/39781/}}} \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}shravya\_kavali2 \\ \uline{cheatography.com/shravya-kavali2} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 6th August, 2023.\\ 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{tabularx}{17.67cm}{x{7.2534 cm} x{10.0166 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Math Library}} \tn % Row 0 \SetRowColor{LightBackground} Math is a final class in java & Which means it cannot be inherited \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Math.abs(-1) & 1 //returns the absolute value \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} Math.ceil(-1.9) & returns: -1.0 //Returns the smallest integer that is greater than or equal to the specified number. \tn % Row Count 9 (+ 5) % Row 3 \SetRowColor{white} \seqsplit{Math.floor(-1.9)} & returns: -2.0 // Returns the largest integer that is less than or equal to the specified number. \tn % Row Count 14 (+ 5) % Row 4 \SetRowColor{LightBackground} Math.max(1, 2) & Returns the larger of the two specified numbers. \tn % Row Count 17 (+ 3) % Row 5 \SetRowColor{white} Math.min(1, 2) & returns: 1 \tn % Row Count 18 (+ 1) % Row 6 \SetRowColor{LightBackground} Math.pow(2, 3) & returns: 8.0, Returns the value of the first argument raised to the power of the second argument. \tn % Row Count 23 (+ 5) % Row 7 \SetRowColor{white} Math.random() & returns: 0.0 \textless{}= x \textless{} 1.0, Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0. \tn % Row Count 29 (+ 6) % Row 8 \SetRowColor{LightBackground} Math.round(1.1) & returns: 1, Returns the closest long or int, as indicated by the method's return type, to the argument \tn % Row Count 34 (+ 5) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{7.2534 cm} x{10.0166 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Math Library (cont)}} \tn % Row 9 \SetRowColor{LightBackground} Math.round(1.5) & returns: 2, \tn % Row Count 1 (+ 1) % Row 10 \SetRowColor{white} Math.sqrt(4) & returns: 2.0, Returns the correctly rounded positive square root of a double value. \tn % Row Count 5 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{2.0244 cm} x{3.7114 cm} x{11.1342 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Primitive Data types}} \tn % Row 0 \SetRowColor{LightBackground} byte & Size: 1 byte & Range: -128 to 127 \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} short & Size: 2 bytes & Range: -32,768 to 32,767 \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} int & Size: 4 bytes & Range: -2,147,483,648 to 2,147,483,647 \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} long & Size: 8 bytes & Range: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 \tn % Row Count 9 (+ 3) % Row 4 \SetRowColor{LightBackground} float & Size: 4 bytes & Range: 3.4e−038 to 3.4e+038 \tn % Row Count 11 (+ 2) % Row 5 \SetRowColor{white} \seqsplit{double} & Size: 8 bytes & Range: 1.7e−308 to 1.7e+308 \tn % Row Count 13 (+ 2) % Row 6 \SetRowColor{LightBackground} \seqsplit{boolean} & Size: 1 bit & Range: true or false \tn % Row Count 15 (+ 2) % Row 7 \SetRowColor{white} char & Size: 2 bytes & Range: 0 to 65,536 \tn % Row Count 17 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{7.9442 cm} x{9.3258 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Operators}} \tn % Row 0 \SetRowColor{LightBackground} a * b & Multiplication \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{a + b} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{a - b} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} a / b & Division \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} a \% b & Modulo \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} a++ & Postincrement \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} ++a & Preincrement \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} b-{}- & Postdecrement \tn % Row Count 8 (+ 1) % Row 8 \SetRowColor{LightBackground} -{}-b & Predecrement \tn % Row Count 9 (+ 1) % Row 9 \SetRowColor{white} a operator= 3 & +, -, *, /, \%, \textless{}\textless{}, \textgreater{}\textgreater{}, \textgreater{}\textgreater{}\textgreater{} \tn % Row Count 11 (+ 2) % Row 10 \SetRowColor{LightBackground} a operator 0b1010 & \&, |, \textasciicircum{} \tn % Row Count 12 (+ 1) % Row 11 \SetRowColor{white} a \seqsplit{relationalOperator} b & ==, !=, \textless{}, \textless{}=, \textgreater{}, \textgreater{}= \tn % Row Count 14 (+ 2) % Row 12 \SetRowColor{LightBackground} a logicalOperator b & \&\&, ||, \tn % Row Count 16 (+ 2) % Row 13 \SetRowColor{white} !x & not operator \tn % Row Count 17 (+ 1) % Row 14 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{TODO: terenary} \tn % Row Count 18 (+ 1) % Row 15 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{TODO: shift operator} \tn % Row Count 19 (+ 1) % Row 16 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{} \tn % Row Count 19 (+ 0) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{loops}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{for (int number : numbers) \{ \seqsplit{System.out.println("Element:} " + number); \}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{for (int i = 0; i \textless{} numbers.size(); i++) \{ int element = numbers.get(i); \seqsplit{System.out.println("Element} at index " + i + ": " + element); \}} \tn % Row Count 5 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Set}} \tn % Row 0 \SetRowColor{LightBackground} The set interface is present in java.util package & which is extended from collection interface \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} Interfaces extended from Set interface: & SortedSet, NavigableSet \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} Classes that implements Set Interface & HashSet, EnumSet, LinkedHashSet, TreeSet \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} SortedSet Interface & contains the methods inherited from the Set interface and adds a feature that stores all the elements in this interface to be stored in a sorted manner \tn % Row Count 15 (+ 8) % Row 4 \SetRowColor{LightBackground} Navigable Interface: & provides the implementation to navigate through the Set. \tn % Row Count 18 (+ 3) % Row 5 \SetRowColor{white} Treeset & implementation of a self-balancing tree \tn % Row Count 20 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{set is implemented using hash table \newline set is unordered \newline set does not allow duplicate elements \newline set allows null elements} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Treeset}} \tn % Row 0 \SetRowColor{LightBackground} Set\textless{}Integer\textgreater{} treeSet = new TreeSet\textless{}Integer\textgreater{}(); & Set interface does not have ceiling() method \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} TreeSet\textless{}Integer\textgreater{} treeSet = new TreeSet\textless{}Integer\textgreater{}(); & if we use Set interface rather than TreeSet class, we cannot use ceiling() method \tn % Row Count 8 (+ 5) % Row 2 \SetRowColor{LightBackground} treeSet.add(10); & adds the element to the treeset \tn % Row Count 10 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{\seqsplit{treeSet2.addAll(treeSet);}} \tn % Row Count 11 (+ 1) % Row 4 \SetRowColor{LightBackground} \seqsplit{System.out.println("treeSet2} after adding elements" + treeSet2); & print treeeSet \tn % Row Count 15 (+ 4) % Row 5 \SetRowColor{white} treeSet.remove(20); & removes the specific element from the treeset \tn % Row Count 18 (+ 3) % Row 6 \SetRowColor{LightBackground} for (Integer item : treeSet) \{ \seqsplit{System.out.println(item);} \} & Iterating over tree set items \tn % Row Count 21 (+ 3) % Row 7 \SetRowColor{white} Iterator\textless{}Integer\textgreater{} iterator = treeSet.iterator(); & Iterating using iterator \tn % Row Count 24 (+ 3) % Row 8 \SetRowColor{LightBackground} Iterator\textless{}Integer\textgreater{} descendingIterator = \seqsplit{treeSet.descendingIterator();} & returns an iterator over the elements in this set in descending order. \tn % Row Count 28 (+ 4) % Row 9 \SetRowColor{white} int value1 = \seqsplit{treeSet.ceiling(25);} & returns the least element in this set greater than or equal to the given element \tn % Row Count 32 (+ 4) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Treeset (cont)}} \tn % Row 10 \SetRowColor{LightBackground} int value2 = treeSet.floor(25); & returns the greatest element in this set less than or equal to the given element \tn % Row Count 4 (+ 4) % Row 11 \SetRowColor{white} Set\textless{}Integer\textgreater{} descendingSet = \seqsplit{treeSet.descendingSet();} & returns a reverse order view of the elements contained in this set. \tn % Row Count 8 (+ 4) % Row 12 \SetRowColor{LightBackground} Set\textless{}Integer\textgreater{} headSet = \seqsplit{treeSet.headSet(30);} & returns a view of the portion of this set whose elements are strictly less than toElement. \tn % Row Count 13 (+ 5) % Row 13 \SetRowColor{white} Set\textless{}Integer\textgreater{} headSet2 = treeSet.headSet(30, true); & returns a view of the portion of this set whose elements are less than or equal to toElement. \tn % Row Count 18 (+ 5) % Row 14 \SetRowColor{LightBackground} Set\textless{}Integer\textgreater{} tailSet = \seqsplit{treeSet.tailSet(30);} & returns a view of the portion of this set whose elements are greater than or equal to fromElement. \tn % Row Count 23 (+ 5) % Row 15 \SetRowColor{white} Set\textless{}Integer\textgreater{} tailSet2 = treeSet.tailSet(30, false); & returns a view of the portion of this set whose elements are strictly greater than fromElement. \tn % Row Count 28 (+ 5) % Row 16 \SetRowColor{LightBackground} Set\textless{}Integer\textgreater{} subSet = treeSet.subSet(20, 40); & returns a view of the portion of this set whose elements range from fromElement, inclusive, to toElement, exclusive. \tn % Row Count 34 (+ 6) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Treeset (cont)}} \tn % Row 17 \SetRowColor{LightBackground} Set\textless{}Integer\textgreater{} subSet2 = treeSet.subSet(20, true, 40, true); & returns a view of the portion of this set whose elements range from fromElement, inclusive, to toElement, inclusive. \tn % Row Count 6 (+ 6) % Row 18 \SetRowColor{white} Integer pollFirst = \seqsplit{treeSet.pollFirst();} & retrieves and removes the first (lowest) element, or returns null if this set is empty. \tn % Row Count 11 (+ 5) % Row 19 \SetRowColor{LightBackground} Integer pollLast = treeSet.pollLast(); & retrieves and removes the last (highest) element, or returns null if this set is empty. \tn % Row Count 16 (+ 5) % Row 20 \SetRowColor{white} boolean remove = treeSet.remove(20); & returns true if this set contained the specified element \tn % Row Count 19 (+ 3) % Row 21 \SetRowColor{LightBackground} boolean isEmpty = treeSet.isEmpty(); & returns true if this set contains no elements. \tn % Row Count 22 (+ 3) % Row 22 \SetRowColor{white} int size = treeSet.size(); & returns the number of elements in this set (its cardinality). \tn % Row Count 26 (+ 4) % Row 23 \SetRowColor{LightBackground} boolean contains = \seqsplit{treeSet.contains(20);} & returns true if this set contains the specified element. \tn % Row Count 29 (+ 3) % Row 24 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{treeSet.clear();} \tn % Row Count 30 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{TreeSet is implemented using a tree structure(red-black tree in algorithm book) \newline TreeSet is ordered, sorted, and navigable \newline TreeSet does not allow duplicate elements \newline TreeSet allows null elements} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.1169 cm} x{9.1531 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{LinkedHashSet}} \tn % Row 0 \SetRowColor{LightBackground} create a linkedHashSet of characters & Set\textless{}Character\textgreater{} linkedHashSet = new LinkedHashSet\textless{}Character\textgreater{}(); \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} add element & \seqsplit{linkedHashSet.add('a');} \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} remove the element & \seqsplit{linkedHashSet.remove('a');} \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} check if the element is present & \seqsplit{linkedHashSet.contains('a')} \tn % Row Count 9 (+ 2) % Row 4 \SetRowColor{LightBackground} size & linkedHashSet.size() \tn % Row Count 10 (+ 1) % Row 5 \SetRowColor{white} is empty & \seqsplit{linkedHashSet.isEmpty()} \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} Iterator & Iterator iterator = \seqsplit{linkedHashSet.iterator();} \tn % Row Count 15 (+ 3) % Row 7 \SetRowColor{white} to Array & \seqsplit{linkedHashSet.toArray()} \tn % Row Count 17 (+ 2) % Row 8 \SetRowColor{LightBackground} to string & \seqsplit{linkedHashSet.toString()} \tn % Row Count 19 (+ 2) % Row 9 \SetRowColor{white} equals & \seqsplit{linkedHashSet.equals(linkedHashSet)} \tn % Row Count 21 (+ 2) % Row 10 \SetRowColor{LightBackground} hashCode() & \seqsplit{linkedHashSet.hashCode()} \tn % Row Count 23 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{linkedHashSet is a subclass of HashSet \newline linkedHashSet maintains insertion order \newline linkedHashSet is slower than HashSet \newline linkedHashSet is faster than TreeSet \newline when to use: when you want to maintain insertion order \newline when not to use: when you want to sort the elements} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.4623 cm} x{8.8077 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{HashSet}} \tn % Row 0 \SetRowColor{LightBackground} Creating the hashSet & Set\textless{}String\textgreater{} hashSet = new HashSet\textless{}String\textgreater{}(); \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} Adding element & \seqsplit{hashSet.add("element1");} \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} Print hashSet & \seqsplit{System.out.println("hashset} after adding elements" + hashSet); \tn % Row Count 9 (+ 4) % Row 3 \SetRowColor{white} remove element & \seqsplit{hashSet.remove("element2");} \tn % Row Count 11 (+ 2) % Row 4 \SetRowColor{LightBackground} Iterating over hash set items & for (String item : hashSet) \{System.out.println(item);\} \tn % Row Count 14 (+ 3) % Row 5 \SetRowColor{white} // Iterating using iterator & Iterator\textless{}String\textgreater{} iterator = hashSet.iterator(); \tn % Row Count 17 (+ 3) % Row 6 \SetRowColor{LightBackground} checking if hashSet contains an element & \seqsplit{hashSet.contains("element1")} \tn % Row Count 20 (+ 3) % Row 7 \SetRowColor{white} checking if hashSet is empty & hashSet.isEmpty() \tn % Row Count 22 (+ 2) % Row 8 \SetRowColor{LightBackground} checking size of hashSet & hashSet.size() \tn % Row Count 24 (+ 2) % Row 9 \SetRowColor{white} clearing hashSet & hashSet.clear(); \tn % Row Count 25 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{Hashset is implemented using hash table \newline Hashset is unordered \newline Hashset does not allow duplicate elements \newline Hashset allows null elements} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Enum hashset}} \tn % Row 0 \SetRowColor{LightBackground} create enumSet & EnumSet\textless{}Days\textgreater{} hashSet = \seqsplit{EnumSet.of(Days.MONDAY}, Days.TUESDAY, Days.WEDNESDAY, Days.THURSDAY, Days.FRIDAY); \tn % Row Count 6 (+ 6) % Row 1 \SetRowColor{white} {[}MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY{]} & EnumSet\textless{}Days\textgreater{} workingDays = \seqsplit{EnumSet.range(Days.MONDAY}, Days.FRIDAY); \tn % Row Count 10 (+ 4) % Row 2 \SetRowColor{LightBackground} {[}SATURDAY, SUNDAY{]} & EnumSet\textless{}Days\textgreater{} weekEnds = \seqsplit{EnumSet.complementOf(workingDays);} \tn % Row Count 13 (+ 3) % Row 3 \SetRowColor{white} {[}MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY{]} & EnumSet\textless{}Days\textgreater{} allDays = \seqsplit{EnumSet.allOf(Days.class);} \tn % Row Count 17 (+ 4) % Row 4 \SetRowColor{LightBackground} {[}{]} & EnumSet\textless{}Days\textgreater{} noDays = \seqsplit{EnumSet.noneOf(Days.class);} \tn % Row Count 20 (+ 3) % Row 5 \SetRowColor{white} add & \seqsplit{noDays.add(Days.MONDAY);} \tn % Row Count 22 (+ 2) % Row 6 \SetRowColor{LightBackground} remove & \seqsplit{noDays.remove(Days.MONDAY);} \tn % Row Count 24 (+ 2) % Row 7 \SetRowColor{white} check if element is present & \seqsplit{noDays.contains(Days.MONDAY)} \tn % Row Count 26 (+ 2) % Row 8 \SetRowColor{LightBackground} check if enum hashset are equal & \seqsplit{weekDays.equals(noDays)} \tn % Row Count 28 (+ 2) % Row 9 \SetRowColor{white} iterator & Iterator iterator = noDays.iterator(); \tn % Row Count 30 (+ 2) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Enum hashset (cont)}} \tn % Row 10 \SetRowColor{LightBackground} get the size & noDays.size() \tn % Row Count 1 (+ 1) % Row 11 \SetRowColor{white} & noDays.toArray() \tn % Row Count 2 (+ 1) % Row 12 \SetRowColor{LightBackground} & noDays.clear(); \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{when to use: when you want to use a set of enum constants \newline when not to use: when you want to use a set of non-enum constants} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \end{document}