\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{yunshu (xys)} \pdfinfo{ /Title (java.pdf) /Creator (Cheatography) /Author (yunshu (xys)) /Subject (Java 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}{FF6600} \definecolor{LightBackground}{HTML}{FFF5EF} \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 Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{yunshu (xys)} via \textcolor{DarkBackground}{\uline{cheatography.com/130138/cs/25835/}}} \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}yunshu (xys) \\ \uline{cheatography.com/xys} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 27th December, 2020.\\ Updated 28th December, 2020.\\ 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}{// import java.lang.Number;}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{8.4cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/xys_1608756710_number_classes.jpg}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Number Methods}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Integer a = 20;} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} a.byteValue(); a.shortValue(); a.intValue(); a.longValue(); a.floatValue(); a.doubleValue() & The method converts the value of the Number Object that invokes the method to the primitive data type that is returned from the method. \tn % Row Count 8 (+ 7) % Row 2 \SetRowColor{LightBackground} a.compareTopublic int compareTo( NumberSubClass same\_type ) & Compares this Number object to the argument. \tn % Row Count 11 (+ 3) % Row 3 \SetRowColor{white} a. equals(Object o) & Determines whether this number object is equal to the argument. \tn % Row Count 15 (+ 4) % Row 4 \SetRowColor{LightBackground} Number.valueOf(int i/String s/ String s, int radix) & The valueOf method returns the Integer holding the value of the argument passed. \tn % Row Count 19 (+ 4) % Row 5 \SetRowColor{white} a. toString() & string representation \tn % Row Count 21 (+ 2) % Row 6 \SetRowColor{LightBackground} Math.abs() & absolute value \tn % Row Count 22 (+ 1) % Row 7 \SetRowColor{white} Math.ceil() & The method ceil gives the smallest integer that is greater than or equal to the argument. \tn % Row Count 27 (+ 5) % Row 8 \SetRowColor{LightBackground} Math.rint() & Returns the integer that is closest in value to the argument. Returned as a double. \tn % Row Count 32 (+ 5) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Number Methods (cont)}} \tn % Row 9 \SetRowColor{LightBackground} Math.round() & Returns the closest long or int, as indicated by the method's return type to the argument. \tn % Row Count 5 (+ 5) % Row 10 \SetRowColor{white} Math.min(a,b) & Returns the smaller of the two arguments. \tn % Row Count 8 (+ 3) % Row 11 \SetRowColor{LightBackground} Math.max(a,b) & Returns the larger of the two arguments. \tn % Row Count 10 (+ 2) % Row 12 \SetRowColor{white} Math.exp() & Returns the base of the natural logarithms, e, to the power of the argument. \tn % Row Count 14 (+ 4) % Row 13 \SetRowColor{LightBackground} Math.log() & Returns the natural logarithm of the argument. \tn % Row Count 17 (+ 3) % Row 14 \SetRowColor{white} Math.pow(a,b) & Returns the value of the first argument raised to the power of the second argument. \tn % Row Count 22 (+ 5) % Row 15 \SetRowColor{LightBackground} Math.sqrt() & Returns the square root of the argument. \tn % Row Count 24 (+ 2) % Row 16 \SetRowColor{white} Math.sin() & Returns the sine of the specified double value. \tn % Row Count 27 (+ 3) % Row 17 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Math.cos(); Math.tan(); Math.asin(); Math.acos(); Math.atan(); Math.atan2();} \tn % Row Count 29 (+ 2) % Row 18 \SetRowColor{white} Math.toDegree() & Converts the argument to degrees. \tn % Row Count 31 (+ 2) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Number Methods (cont)}} \tn % Row 19 \SetRowColor{LightBackground} Math. toRadians() & Converts the argument to radians. \tn % Row Count 2 (+ 2) % Row 20 \SetRowColor{white} Math.random() & Returns a random number. \tn % Row Count 4 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{StringBuilder}} \tn % Row 0 \SetRowColor{LightBackground} `StringBuilder sb = new StringBuilder({\emph{capacity}} or {\emph{string}});` & creat a StringBuilder \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} `sb.append(obj);` & append string representation of obj to this SB \tn % Row Count 7 (+ 3) % Row 2 \SetRowColor{LightBackground} `sb.capacity();` & return the current capacity \tn % Row Count 9 (+ 2) % Row 3 \SetRowColor{white} `sb.charAt(index);` & Returns the char value in this sequence at the specified index. \tn % Row Count 13 (+ 4) % Row 4 \SetRowColor{LightBackground} `sb.delete(start,end\_exclusive);` & Removes the characters in a substring of this sequence. \tn % Row Count 16 (+ 3) % Row 5 \SetRowColor{white} \seqsplit{`sb.deleteCharAt(index);`} & Removes the char at the specified position in this sequence. \tn % Row Count 19 (+ 3) % Row 6 \SetRowColor{LightBackground} `getChars(int srcBegin, int srcEnd, char{[}{]} dst, int dstBegin);` & Characters are copied from this sequence into the destination character array dst. \tn % Row Count 24 (+ 5) % Row 7 \SetRowColor{white} `sb.indexOf(string,{\emph{from}});` & Returns the index within this string of the first occurrence of the specified substring. \tn % Row Count 29 (+ 5) % Row 8 \SetRowColor{LightBackground} `sb.insert(index,obj)` & Inserts the string representation of the boolean argument into this sequence. \tn % Row Count 33 (+ 4) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{StringBuilder (cont)}} \tn % Row 9 \SetRowColor{LightBackground} `sb.replace(int start, int end, String str);` & Replaces the characters in a substring of this sequence with characters in the specified String. \tn % Row Count 5 (+ 5) % Row 10 \SetRowColor{white} `sb.reverse()` & Causes this character sequence to be replaced by the reverse of the sequence. \tn % Row Count 9 (+ 4) % Row 11 \SetRowColor{LightBackground} `sb.setCharAt(int index, char ch);` & The character at the specified index is set to ch. \tn % Row Count 12 (+ 3) % Row 12 \SetRowColor{white} `sb.subSequence(int start, int end)` & Returns a new character sequence that is a subsequence of this sequence. \tn % Row Count 16 (+ 4) % Row 13 \SetRowColor{LightBackground} `sb.substring(int start,{\emph{end}})` & Returns a new String that contains a subsequence of characters currently contained in this character sequence. \tn % Row Count 22 (+ 6) % Row 14 \SetRowColor{white} `sb.toString()` & Returns a string representing the data in this sequence. \tn % Row Count 25 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Thread}} \tn \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{{\bf{Creating a thread in Java is done like this:}} \newline % Row Count 1 (+ 1) ` Thread thread = new Thread();` \newline % Row Count 2 (+ 1) {\bf{To start the thread}} \newline % Row Count 3 (+ 1) ` thread.start();` \newline % Row Count 4 (+ 1) {\bf{To join the thread}} \newline % Row Count 5 (+ 1) `thread.join()` \newline % Row Count 6 (+ 1) {\bf{Thread subclass}} \newline % Row Count 7 (+ 1) `public class MyThread extends Thread \{` \newline % Row Count 8 (+ 1) `public void run()\{System.out.println("MyThread running"); \}` \newline % Row Count 10 (+ 2) `\}` \newline % Row Count 11 (+ 1) `MyThread myThread = new MyThread();` \newline % Row Count 12 (+ 1) ` myTread.start();` \newline % Row Count 13 (+ 1) {\emph{OR:}} \newline % Row Count 14 (+ 1) `Thread thread = new Thread()\{` \newline % Row Count 15 (+ 1) `public void run()\{` \newline % Row Count 16 (+ 1) ` \seqsplit{System.out.println("Thread} Running");\}` \newline % Row Count 17 (+ 1) \}` \newline % Row Count 18 (+ 1) `thread.start();` \newline % Row Count 19 (+ 1) {\bf{Runnable Interface Implementation}} \newline % Row Count 20 (+ 1) `public interface Runnable() \{public void run();\}` \newline % Row Count 22 (+ 2) {\bf{To implement a Runnable}} \newline % Row Count 23 (+ 1) 1. Java Class Implements Runnable \newline % Row Count 24 (+ 1) `public class MyRunnable implements Runnable \{` \newline % Row Count 25 (+ 1) ` public void run()\{` \newline % Row Count 26 (+ 1) ` \seqsplit{System.out.println("MyRunnable} running"); \}` \newline % Row Count 28 (+ 2) `\}` \newline % Row Count 29 (+ 1) 2. Anonymous Implementation of Runnable \newline % Row Count 30 (+ 1) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Thread (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{`Runnable myRunnable =` \newline % Row Count 1 (+ 1) ` new Runnable()\{` \newline % Row Count 2 (+ 1) `public void run()\{` \newline % Row Count 3 (+ 1) \seqsplit{`System.out.println("Runnable} running");\}` \newline % Row Count 5 (+ 2) \}` \newline % Row Count 6 (+ 1) 3. Java Lambda Implementation of Runnable \newline % Row Count 7 (+ 1) `Runnable runnable = () -\textgreater{} \{ \seqsplit{System.out.println("Lambda} Runnable running"); \};` \newline % Row Count 9 (+ 2) {\bf{Starting a Thread With a Runnable}} \newline % Row Count 10 (+ 1) `Runnable runnable = new MyRunnable();` // or an anonymous class, or lambda... \newline % Row Count 12 (+ 2) `Thread thread = new Thread(runnable);` \newline % Row Count 13 (+ 1) `thread.start();`% Row Count 14 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Synchronization}} \newline {\bf{1. Synchronized Instance Methods}} \newline `public synchronized void synchronisedCalculate()` \newline `\{setSum(getSum() + 1);\}` \newline \newline \newline {\bf{2. Synchronized Static Methods}} \newline `public static synchronized void syncStaticCalculate() ` \newline ` \{staticSum = staticSum + 1;\}` \newline {\bf{{\emph{* \newline \newline }}3. Synchronized Blocks Within Methods}}* \newline `public void \seqsplit{performSynchronisedTask()} \{` \newline `//unsynchronized part` \newline // ... \newline ` synchronized (this/obj) \{` \newline `setCount(getCount()+1);\}\}`} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4.72 cm} x{3.28 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{import java.time}} \tn % Row 0 \SetRowColor{LightBackground} `import java.time.LocalDate;` & yyyy-MM-dd \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} `LocalDate myObj = LocalDate.now(); \seqsplit{System.out.println(myObj);`} & "2020-12-28" \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} `import java.time.LocalTime;` & HH-mm-ss-ns \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} ` LocalTime myObj = LocalTime.now(); \seqsplit{System.out.println(myObj);`} & \seqsplit{"00:01:02.290985"} \tn % Row Count 10 (+ 3) % Row 4 \SetRowColor{LightBackground} `import \seqsplit{java.time.LocalDateTime;} ` & \seqsplit{yyyy-MM-dd-HH-mm-ss-ns} \tn % Row Count 12 (+ 2) % Row 5 \SetRowColor{white} `LocalDateTime myDateObj = LocalDateTime.now(); \seqsplit{System.out.println(myDateObj);`} & \seqsplit{"2020-12-28T00:01:02}.311139" \tn % Row Count 16 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{source: \seqsplit{https://www.w3schools.com/java/java\_date.asp}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{import java.util.HashMap;}} \tn % Row 0 \SetRowColor{LightBackground} `public void clear()` & This method removes all of the mappings from this map. \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} `public boolean containsKey(Object key)` & This method returns true if this map contains a mapping for the specified key. \tn % Row Count 7 (+ 4) % Row 2 \SetRowColor{LightBackground} `public boolean \seqsplit{containsValue(Object} value)` & This method returns true if this map maps one or more keys to the specified value. \tn % Row Count 12 (+ 5) % Row 3 \SetRowColor{white} `public Set\textless{}Map.Entry\textless{}K,V\textgreater{}\textgreater{} entrySet()` & This method returns a Set view of the mappings contained in this map. \tn % Row Count 16 (+ 4) % Row 4 \SetRowColor{LightBackground} `public V get(Object key)` & This method returns the value to which the specified key is mapped, or null if this map contains no mapping for the key. \tn % Row Count 22 (+ 6) % Row 5 \SetRowColor{white} `public boolean isEmpty()` & This method returns true if this map contains no key-value mapping. \tn % Row Count 26 (+ 4) % Row 6 \SetRowColor{LightBackground} `public Set\textless{}K\textgreater{} keySet()` & This method returns a Set view of the keys contained in this map. \tn % Row Count 30 (+ 4) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{import java.util.HashMap; (cont)}} \tn % Row 7 \SetRowColor{LightBackground} `public V put(K key, V value)` & This method associates the specified value with the specified key in this map. \tn % Row Count 4 (+ 4) % Row 8 \SetRowColor{white} `public void putAll(Map\textless{}? extends K,? extends V\textgreater{} m)` & This method copies all of the mappings from the specified map to this map. \tn % Row Count 8 (+ 4) % Row 9 \SetRowColor{LightBackground} `public V remove(Object key)` & This method removes the mapping for the specified key from this map if present. \tn % Row Count 12 (+ 4) % Row 10 \SetRowColor{white} `public int size()` & This method returns the number of key-value mappings in this map. \tn % Row Count 16 (+ 4) % Row 11 \SetRowColor{LightBackground} `public Collection\textless{}V\textgreater{} values()` & This method returns a Collection view of the values contained in this map. \tn % Row Count 20 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{import java.util.PriorityQueue;}} \tn % Row 0 \SetRowColor{LightBackground} `public boolean add(E e)` & This method inserts the specified element into this priority queue. \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} `public boolean offer(E e)` & This method inserts the specified element into this priority queue. \tn % Row Count 8 (+ 4) % Row 2 \SetRowColor{LightBackground} `public void clear() ` & This method removes all of the elements from this priority queue. \tn % Row Count 12 (+ 4) % Row 3 \SetRowColor{white} `public boolean contains(Object o)` & This method returns true if this queue contains the specified element. \tn % Row Count 16 (+ 4) % Row 4 \SetRowColor{LightBackground} `public Iterator\textless{}E\textgreater{} iterator()` & This method returns an iterator over the elements in this queue. \tn % Row Count 20 (+ 4) % Row 5 \SetRowColor{white} `public E peek() ` & This method retrieves, but does not remove, the head of this queue, or returns null if this queue is empty. \tn % Row Count 26 (+ 6) % Row 6 \SetRowColor{LightBackground} `This method retrieves and removes the head of this queue, or returns null if this queue is empty.` & This method retrieves and removes the head of this queue, or returns null if this queue is empty. \tn % Row Count 31 (+ 5) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{import java.util.PriorityQueue; (cont)}} \tn % Row 7 \SetRowColor{LightBackground} `public boolean remove(Object o)` & This method removes a single instance of the specified element from this queue, if it is present. \tn % Row Count 5 (+ 5) % Row 8 \SetRowColor{white} `public int size()` & This method returns the number of elements in this collection. \tn % Row Count 9 (+ 4) % Row 9 \SetRowColor{LightBackground} `public Object{[}{]} toArray()` & This method returns an array containing all of the elements in this queue. \tn % Row Count 13 (+ 4) % Row 10 \SetRowColor{white} `public \textless{}T\textgreater{} T{[}{]} toArray(T{[}{]} a) ` & This method returns an array containing all of the elements in this queue; the runtime type of the returned array is that of the specified array. \tn % Row Count 21 (+ 8) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{The java.util.PriorityQueue class is an unbounded priority queue based on a priority heap.Following are the important points about PriorityQueue \newline \newline - The elements of the priority queue are ordered according to their natural ordering, or by a Comparator provided at queue construction time, depending on which constructor is used. \newline \newline - A priority queue does not permit null elements. \newline \newline - A priority queue relying on natural ordering also does not permit insertion of non-comparable objects.} \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}{import java.util.Stream;}} \tn \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{\seqsplit{https://developer.ibm.com/zh/languages/java/articles/j-lo-java8streamapi/}% Row Count 2 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{bye} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Character class}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Character c = '1';} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \seqsplit{Character.isLetter()} & The method determines whether the specified char value is a letter. \tn % Row Count 5 (+ 4) % Row 2 \SetRowColor{LightBackground} Character.isDigit() & The method determines whether the specified char value is a digit. \tn % Row Count 9 (+ 4) % Row 3 \SetRowColor{white} \seqsplit{Character.isLetterOrDigit(char} ch) & Determines if the specified character is a letter or digit. \tn % Row Count 12 (+ 3) % Row 4 \SetRowColor{LightBackground} \seqsplit{Character.digit(char} ch, int radix) & Returns the numeric value of the character ch in the specified radix. \tn % Row Count 16 (+ 4) % Row 5 \SetRowColor{white} \seqsplit{Character.forDigit(int} digit, int radix) & Determines the character representation for a specific digit in the specified radix. \tn % Row Count 21 (+ 5) % Row 6 \SetRowColor{LightBackground} \seqsplit{Character.isWhitespace()} & Determines whether the specified char value is white space. \tn % Row Count 24 (+ 3) % Row 7 \SetRowColor{white} Character. isUpperCase() & Determines whether the specified char value is uppercase. \tn % Row Count 27 (+ 3) % Row 8 \SetRowColor{LightBackground} Character. toUpperCase() & Determines whether the specified char value is lowercase. \tn % Row Count 30 (+ 3) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Character class (cont)}} \tn % Row 9 \SetRowColor{LightBackground} \seqsplit{Character.toLowerCase()} & Returns the lowercase form of the specified char value. \tn % Row Count 3 (+ 3) % Row 10 \SetRowColor{white} \seqsplit{Character.toString()} & Returns a String object representing the specified character value that is, a one-character string. \tn % Row Count 8 (+ 5) % Row 11 \SetRowColor{LightBackground} Character. codePointAt(seq,index) & return the ASCII value of char at index in seq \tn % Row Count 11 (+ 3) % Row 12 \SetRowColor{white} c.charValue(); & return the ASCII value of this char. \tn % Row Count 13 (+ 2) % Row 13 \SetRowColor{LightBackground} \seqsplit{Character.getNumericValue(char} ch) & Returns the int value that the specified Unicode character represents. \tn % Row Count 17 (+ 4) % Row 14 \SetRowColor{white} \seqsplit{Character.isSpaceChar(char} ch) & Determines if the specified character is a Unicode space character. \tn % Row Count 21 (+ 4) % Row 15 \SetRowColor{LightBackground} \seqsplit{Character.isWhitespace(char} ch) & Determines if the specified character is white space according to Java. \tn % Row Count 25 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{String class}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{String s = "123"} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} s.charAt() & This method returns the character located at the String's specified index. The string indexes start from zero. \tn % Row Count 7 (+ 6) % Row 2 \SetRowColor{LightBackground} s.compareTo() & This method compares two strings lexicographically. \tn % Row Count 10 (+ 3) % Row 3 \SetRowColor{white} \seqsplit{s.compareToIgnoreCase()} & Compares two strings lexicographically, ignoring case differences. \tn % Row Count 14 (+ 4) % Row 4 \SetRowColor{LightBackground} s.concat() & This method appends one String to the end of another. The method returns a String with the value of the String passed into the method, appended to the end of the String, used to invoke this method. \tn % Row Count 24 (+ 10) % Row 5 \SetRowColor{white} \seqsplit{s.contentEqual(StringBuilder} sb) & This method returns true if and only if this String represents the same sequence of characters as specified in StringBuffer. \tn % Row Count 31 (+ 7) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{String class (cont)}} \tn % Row 6 \SetRowColor{LightBackground} s.endsWith() & This method tests if this string ends with the specified suffix. \tn % Row Count 4 (+ 4) % Row 7 \SetRowColor{white} s.equals() & This method compares this string to the specified object. The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object. \tn % Row Count 15 (+ 11) % Row 8 \SetRowColor{LightBackground} \seqsplit{s.equalsIgnoreCase()} & This method compares this String to another String, ignoring case considerations. Two strings are considered equal ignoring case, if they are of the same length, and corresponding characters in the two strings are equal ignoring case. \tn % Row Count 27 (+ 12) % Row 9 \SetRowColor{white} s.getChars(int srcBegin, int srcEnd, char{[}{]} dst, int dstBegin) & This method copies characters from this string into the destination character array. \tn % Row Count 32 (+ 5) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{String class (cont)}} \tn % Row 10 \SetRowColor{LightBackground} s.indexOf(int ch) & Returns the index within this string of the first occurrence of the specified character. \tn % Row Count 5 (+ 5) % Row 11 \SetRowColor{white} s.indexOf(int ch, int fromIndex) & Returns the index within this string of the first occurrence of the specified character, starting the search at the specified index. \tn % Row Count 12 (+ 7) % Row 12 \SetRowColor{LightBackground} s.lastIndexOf(int ch) & Returns the index within this string of the last occurrence of the specified character. \tn % Row Count 17 (+ 5) % Row 13 \SetRowColor{white} s.lastIndexOf(int ch, int fromIndex) & Returns the index within this string of the last occurrence of the specified character, searching backward starting at the specified index. \tn % Row Count 24 (+ 7) % Row 14 \SetRowColor{LightBackground} s.length() & Returns the length of this string. \tn % Row Count 26 (+ 2) % Row 15 \SetRowColor{white} s.matches(regex) & Tells whether or not this string matches the given regular expression. \tn % Row Count 30 (+ 4) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{String class (cont)}} \tn % Row 16 \SetRowColor{LightBackground} \seqsplit{s.regionMatches(boolean} ignoreCase,int this\_offset,String other,int that\_offset,int len)) & This method has two variants which can be used to test if two string regions are equal. \tn % Row Count 5 (+ 5) % Row 17 \SetRowColor{white} s.replace(old,new) & Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar. \tn % Row Count 11 (+ 6) % Row 18 \SetRowColor{LightBackground} s.split(del,{\emph{limit}}) & split the string \tn % Row Count 12 (+ 1) % Row 19 \SetRowColor{white} s.subSequence(beg,end) & Returns a new character sequence that is a subsequence of this sequence. \tn % Row Count 16 (+ 4) % Row 20 \SetRowColor{LightBackground} s.substring(beg,{\emph{end}}) & Returns a new string that is a substring of this string. \tn % Row Count 19 (+ 3) % Row 21 \SetRowColor{white} s.toCharArray() & Converts this string to a new character array. \tn % Row Count 22 (+ 3) % Row 22 \SetRowColor{LightBackground} s.toLowerCase() & Converts all of the characters in this String to lower case using the rules of the default locale. \tn % Row Count 27 (+ 5) % Row 23 \SetRowColor{white} s.toUpperCase & Converts all of the characters in this String to upper case using the rules of the default locale. \tn % Row Count 32 (+ 5) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{String class (cont)}} \tn % Row 24 \SetRowColor{LightBackground} s.trim() & Returns a copy of the string, with leading and trailing whitespace omitted. \tn % Row Count 4 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4.72 cm} x{3.28 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{import java.util.ArrayList;}} \tn % Row 0 \SetRowColor{LightBackground} `ArrayList\textless{}String\textgreater{} cars = new ArrayList\textless{}String\textgreater{}();` & create an Arraylist \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} `cars.get(index);` & get item at index \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} `cars.set(0, "Opel");` & set item at index \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} `cars.remove(0);` & remove item at index \tn % Row Count 9 (+ 2) % Row 4 \SetRowColor{LightBackground} `cars.clear();` & remove all items \tn % Row Count 10 (+ 1) % Row 5 \SetRowColor{white} `cars.size();` & get size of arraylist \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} `import java.util.Collections; ` & Import the Collections class \tn % Row Count 14 (+ 2) % Row 7 \SetRowColor{white} \seqsplit{`Collections.sort(myNumbers);} ` & Sort myNumbers \tn % Row Count 16 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{import java.util.Arrays;}} \tn % Row 0 \SetRowColor{LightBackground} `public static \textless{}T\textgreater{} List\textless{}T\textgreater{} asList(T... a)` & This method returns a fixed-size list backed by the specified array. \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} `public static int binarySearch(arr, {\emph{fromInd}},{\emph{toInd}},target,)` & This method searches the specified array of bytes for the specified value using the binary search algorithm. \tn % Row Count 10 (+ 6) % Row 2 \SetRowColor{LightBackground} `public static \textless{}T\textgreater{} T{[}{]} copyOf(T{[}{]} original, int newLength)` & This method copies the specified array, truncating or padding with nulls (if necessary) so the copy has the specified length. \tn % Row Count 17 (+ 7) % Row 3 \SetRowColor{white} `public static T{[}{]} \seqsplit{copyOfRange(originalArr}, int from, int to)` & This method copies the specified range of the specified array into a new array. \tn % Row Count 21 (+ 4) % Row 4 \SetRowColor{LightBackground} `public static boolean deepEquals(Object{[}{]} a1, Object{[}{]} a2)` & This method returns true if the two specified arrays are deeply equal to one another. \tn % Row Count 26 (+ 5) % Row 5 \SetRowColor{white} `public static boolean equals(Object{[}{]} a, Object{[}{]} a2)` & This method returns true if the two specified arrays of Objects are equal to one another. \tn % Row Count 31 (+ 5) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{import java.util.Arrays; (cont)}} \tn % Row 6 \SetRowColor{LightBackground} `public static void fill(Object{[}{]} a, Object val)` & This method assigns the specified Object reference to each element of the specified array of Objects. \tn % Row Count 6 (+ 6) % Row 7 \SetRowColor{white} `public static void fill(object{[}{]} a, int fromIndex, int toIndex, object val)` & This method assigns the specified Object reference to each element of the specified range of the specified array of Objects. \tn % Row Count 13 (+ 7) % Row 8 \SetRowColor{LightBackground} `public static void sort(Object{[}{]} a)` & This method sorts the specified array of objects into ascending order, according to the natural ordering of its elements. \tn % Row Count 20 (+ 7) % Row 9 \SetRowColor{white} `public static void sort(Object{[}{]} a, int fromIndex, int toIndex)` & This method sorts the specified range of the specified array of objects into ascending order, according to the natural ordering of its elements. \tn % Row Count 28 (+ 8) % Row 10 \SetRowColor{LightBackground} `public static String toString(Object{[}{]} a)` & This method returns a string representation of the contents of the specified array of ints. \tn % Row Count 33 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{import java.util.Collections;}} \tn % Row 0 \SetRowColor{LightBackground} `public static \textless{}T\textgreater{} boolean addAll(Collection\textless{}? super T\textgreater{} c, T.. a)` & This method adds all of the specified elements to the specified collection. \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} `public static \textless{}T\textgreater{} int binarySearch(List\textless{}? extends Comparable\textless{}? super T\textgreater{}\textgreater{} list, T key)` & This method searches the specified list for the specified object using the binary search algorithm. \tn % Row Count 9 (+ 5) % Row 2 \SetRowColor{LightBackground} `public static \textless{}T\textgreater{} void copy(List\textless{}? super T\textgreater{} dest,List\textless{}? extends T\textgreater{} src)` & This method copies all of the elements from one list into another. \tn % Row Count 13 (+ 4) % Row 3 \SetRowColor{white} `public static boolean disjoint(Collection\textless{}?\textgreater{} c1,Collection\textless{}?\textgreater{} c2)` & This method returns true if the two specified collections have no elements in common. \tn % Row Count 18 (+ 5) % Row 4 \SetRowColor{LightBackground} `public static \textless{}T\textgreater{} void fill(List\textless{}? super T\textgreater{} list, T obj)` & This method returns an enumeration over the specified collection. \tn % Row Count 22 (+ 4) % Row 5 \SetRowColor{white} `public static \textless{}T\textgreater{} void fill(List\textless{}? super T\textgreater{} list, T obj)` & This method replaces all of the elements of the specified list with the specified element. \tn % Row Count 27 (+ 5) % Row 6 \SetRowColor{LightBackground} `public static int indexOfSubList(List\textless{}?\textgreater{} source, List\textless{}?\textgreater{} target)` & This method returns the starting position of the first occurrence of the specified target list within the specified source list, or -1 if there is no such occurrence. \tn % Row Count 36 (+ 9) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{import java.util.Collections; (cont)}} \tn % Row 7 \SetRowColor{LightBackground} `public static int lastIndexOfSubList(List\textless{}?\textgreater{} source, List\textless{}?\textgreater{} target)` & This method returns the starting position of the last occurrence of the specified target list within the specified source list, or -1 if there is no such occurrence. \tn % Row Count 9 (+ 9) % Row 8 \SetRowColor{white} `public static \textless{}T extends Object \& Comparable\textless{}? super T\textgreater{}\textgreater{} T max(Collection\textless{}? extends T\textgreater{} coll)` & This method returns the maximum element of the given collection, according to the natural ordering of its elements. \tn % Row Count 15 (+ 6) % Row 9 \SetRowColor{LightBackground} `public static \textless{}T extends Object \& Comparable\textless{}? super T\textgreater{}\textgreater{} T min(Collection\textless{}? extends T\textgreater{} coll)` & This method Returns the minimum element of the given collection, according to the natural ordering of its elements. \tn % Row Count 21 (+ 6) % Row 10 \SetRowColor{white} `public static \textless{}T\textgreater{} boolean replaceAll(List\textless{}T\textgreater{} list,T oldVal,T newVal)` & This method replaces all occurrences of one specified value in a list with another. \tn % Row Count 26 (+ 5) % Row 11 \SetRowColor{LightBackground} `public static void shuffle(List\textless{}?\textgreater{} list)` & This method randomly permutes the specified list using a default source of randomness. \tn % Row Count 31 (+ 5) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{import java.util.Collections; (cont)}} \tn % Row 12 \SetRowColor{LightBackground} `public static void rotate(List\textless{}?\textgreater{} list,int distance)` & This method rotates the elements in the specified list by the specified distance. \tn % Row Count 5 (+ 5) % Row 13 \SetRowColor{white} `public static \textless{}T extends Comparable\textless{}? super T\textgreater{}\textgreater{} void sort(List\textless{}T\textgreater{} list)` & This method sorts the specified list into ascending order, according to the natural ordering of its elements. \tn % Row Count 11 (+ 6) % Row 14 \SetRowColor{LightBackground} `public static void swap(List\textless{}?\textgreater{} list,int i,int j)` & This method swaps the elements at the specified positions in the specified list. \tn % Row Count 15 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.76 cm} x{4.24 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{import java.util.HashSet;}} \tn % Row 0 \SetRowColor{LightBackground} `public boolean add(E e)` & This method adds the specified element to this set if it is not already present. \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} `public void clear()` & This method removes all of the elements from this set. \tn % Row Count 7 (+ 3) % Row 2 \SetRowColor{LightBackground} `public boolean contains(Object o)` & This method returns true if this set contains the specified element. \tn % Row Count 11 (+ 4) % Row 3 \SetRowColor{white} `public boolean isEmpty()` & This method returns true if this set contains no elements. \tn % Row Count 14 (+ 3) % Row 4 \SetRowColor{LightBackground} `public Iterator\textless{}E\textgreater{} iterator()` & This method returns an iterator over the elements in this set. \tn % Row Count 17 (+ 3) % Row 5 \SetRowColor{white} `public boolean remove(Object o)` & This method removes the specified element from this set if it is present. \tn % Row Count 21 (+ 4) % Row 6 \SetRowColor{LightBackground} `public int size()` & This method returns returns the number of elements in this set(its cardinality). \tn % Row Count 25 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.6 cm} x{4.4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{import java.util.Stack}} \tn % Row 0 \SetRowColor{LightBackground} `public boolean empty()` & This method tests if this stack is empty. \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} `public Object peek()` & This method looks at the object at the top of this stack without removing it from the stack. \tn % Row Count 7 (+ 5) % Row 2 \SetRowColor{LightBackground} `public Object pop()` & This method removes the object at the top of this stack and returns that object as the value of this function. \tn % Row Count 12 (+ 5) % Row 3 \SetRowColor{white} `public Object push(Object item)` & This method pushes an item onto the top of this stack. \tn % Row Count 15 (+ 3) % Row 4 \SetRowColor{LightBackground} `public int search(Object o)` & This method returns the 1-based position where an object is on this stack. \tn % Row Count 19 (+ 4) \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}{import java.util.Random}} \tn % Row 0 \SetRowColor{LightBackground} `protected int next(int bits)` & This method generates the next pseudorandom number. \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} `public boolean nextX()` & X = \seqsplit{Boolean/Int/Double/Float/Long} uniformly distributed between 0 and 1 \tn % Row Count 7 (+ 4) % Row 2 \SetRowColor{LightBackground} `public double nextGaussian()` & This method returns the next pseudorandom, Gaussian ("normally") distributed double value with mean 0.0 and standard deviation 1.0 from this random number generator's sequence. \tn % Row Count 15 (+ 8) % Row 3 \SetRowColor{white} `public int nextInt(int n)` & This method returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence. \tn % Row Count 24 (+ 9) % Row 4 \SetRowColor{LightBackground} `public void setSeed(long seed)` & This method sets the seed of this random number generator using a single long seed. \tn % Row Count 28 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}