\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{barbaeguama} \pdfinfo{ /Title (java-functional-interfaces.pdf) /Creator (Cheatography) /Author (barbaeguama) /Subject (Java Functional Interfaces 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}{97DBB0} \definecolor{LightBackground}{HTML}{F2FAF5} \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 Functional Interfaces Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{barbaeguama} via \textcolor{DarkBackground}{\uline{cheatography.com/203153/cs/43228/}}} \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}barbaeguama \\ \uline{cheatography.com/barbaeguama} \\ \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 29th April, 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{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Java Functional Interface}} \tn \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{The functional interface is a simple interface with only one abstract method. A lambda expression can be used through a functional interface in Java 8. We can declare our own/custom functional interface by defining the Single Abstract Method (SAM) in an interface.% Row Count 6 (+ 6) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{4.6629 cm} x{12.6071 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Types}} \tn % Row 0 \SetRowColor{LightBackground} PREDICATE & takes one (or two) argument(s) and returns a boolean \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} UNARY OPERATOR & result and the single argument types are the same \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} BINARY OPERATOR & result and both argument types are the same \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} FUNCTION & result and one (or two) argument(s) types are different \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} SUPPLIER & takes no arguments, returns a value \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} CONSUMER & takes one (or two) arguments and returns no value \tn % Row Count 12 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Notes}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{If the interface accepts primitive arguments: prefixed Double, Int, Long, e.g. DoubleConsumer} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{If the interface produces a primitive result: prefixed ToDouble, ToInt, ToLong, e.g. ToDoubleFunction} \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{If the interface both accepts and produces a primitive: prefixes combined e.g. IntToDoubleFunction} \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{BiConsumer variants that accept an object type and a primitive are prefixed Obj + the primitive, e.g. ObjDoubleConsumer} \tn % Row Count 10 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{3.2053 cm} x{5.5671 cm} x{8.0976 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Predicate}} \tn % Row 0 \SetRowColor{LightBackground} Predicate\textless{}T\textgreater{} & boolean test(T t) & Represents a predicate (boolean-valued function) of one argument (reference type) \tn % Row Count 5 (+ 5) % Row 1 \SetRowColor{white} BiPredicate\textless{}T,U\textgreater{} & boolean test(T t, U u) & Accepts two arguments (reference types) \tn % Row Count 8 (+ 3) % Row 2 \SetRowColor{LightBackground} \seqsplit{DoublePredicate} & e boolean test(double value) & Accepts one double-valued argument \tn % Row Count 11 (+ 3) % Row 3 \SetRowColor{white} \seqsplit{IntPredicate} & boolean test(int value) & Accepts one int-valued argument \tn % Row Count 13 (+ 2) % Row 4 \SetRowColor{LightBackground} \seqsplit{LongPredicate} & boolean test(long value) & Accepts one long-valued argument \tn % Row Count 15 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{3.2053 cm} x{4.8923 cm} x{8.7724 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Supplier}} \tn % Row 0 \SetRowColor{LightBackground} Supplier\textless{}T\textgreater{} & T get() & Represents a supplier of results (reference type) \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \seqsplit{DoubleSupplier} & double \seqsplit{getAsDouble()} & A supplier of double-valued results \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} \seqsplit{IntSupplier} & int getAsInt() & A supplier of int-valued results \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} \seqsplit{LongSupplier} & long \seqsplit{getAsLong()} & A supplier of long-valued results \tn % Row Count 9 (+ 2) % Row 4 \SetRowColor{LightBackground} \seqsplit{BooleanSupplier} & boolean \seqsplit{getAsBoolean()} & A supplier of boolean-valued results \tn % Row Count 12 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{3.7114 cm} x{5.5671 cm} x{7.5915 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Consumer}} \tn % Row 0 \SetRowColor{LightBackground} Consumer\textless{}T\textgreater{} & void accept(T t) & Represents an operation that accepts a single (reference type) input argument and returns no result \tn % Row Count 6 (+ 6) % Row 1 \SetRowColor{white} \seqsplit{DoubleConsumer} & void \seqsplit{accept(double} value) & Accepts a single double-valued argument and returns no result \tn % Row Count 10 (+ 4) % Row 2 \SetRowColor{LightBackground} \seqsplit{IntConsumer} & void accept(int value) & Accepts a single int-valued argument and returns no result \tn % Row Count 14 (+ 4) % Row 3 \SetRowColor{white} \seqsplit{LongConsumer} & void accept(long value) & Accepts a single long-valued argument and returns no result \tn % Row Count 18 (+ 4) % Row 4 \SetRowColor{LightBackground} BiConsumer\textless{}T,U\textgreater{} & void accept(T t, U u) & Represents an operation that accepts two (reference type) input arguments and returns no result \tn % Row Count 24 (+ 6) % Row 5 \SetRowColor{white} ObjDoubleConsumer\textless{}T\textgreater{} & void accept(T t, double value) & Accepts an object-valued and a double-valued argument, and returns no result \tn % Row Count 29 (+ 5) % Row 6 \SetRowColor{LightBackground} ObjIntConsumer\textless{}T\textgreater{} & void accept(T t, int value) & Accepts an object-valued and an int-valued argument, and returns no result \tn % Row Count 34 (+ 5) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{3.7114 cm} x{5.5671 cm} x{7.5915 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Consumer (cont)}} \tn % Row 7 \SetRowColor{LightBackground} ObjLongConsumer\textless{}T\textgreater{} & void accept(T t, long value) & Accepts an object-valued and a long-valued argument, and returns no result \tn % Row Count 5 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{3.374 cm} x{6.748 cm} x{6.748 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{{\bf{Binary Operator}}}} \tn % Row 0 \SetRowColor{LightBackground} BinaryOperator\textless{}T\textgreater{} & T apply(T t, T u) & Represents an operation upon two operands of the same type, producing a result of the same type as the operands (reference type) \tn % Row Count 9 (+ 9) % Row 1 \SetRowColor{white} \seqsplit{DoubleBinaryOperator} & double \seqsplit{applyAsDouble(double} left, double right) & Accepts two double-valued operands and produces a double-valued result \tn % Row Count 14 (+ 5) % Row 2 \SetRowColor{LightBackground} \seqsplit{IntBinaryOperator} & int applyAsInt(int left, int right) & Accepts two int-valued operands and produces an int-valued result \tn % Row Count 19 (+ 5) % Row 3 \SetRowColor{white} \seqsplit{LongBinaryOperator} & long \seqsplit{applyAsLong(long} left, long right) & Accepts two long-valued operands and produces a long-valued result. \tn % Row Count 24 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{3.374 cm} x{6.4106 cm} x{7.0854 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Unary Operator}} \tn % Row 0 \SetRowColor{LightBackground} UnaryOperator\textless{}T\textgreater{} & T apply(T t) & Represents an operation on a single operand that produces a result of the same type as its operand (reference type) \tn % Row Count 8 (+ 8) % Row 1 \SetRowColor{white} \seqsplit{DoubleUnaryOperator} & double \seqsplit{applyAsDouble(double} operand) & Accepts single double-valued operand and produces a double-valued result \tn % Row Count 13 (+ 5) % Row 2 \SetRowColor{LightBackground} \seqsplit{IntUnaryOperator} & int applyAsInt(int operand) & Accepts a single int-valued operand and produces an int-valued result \tn % Row Count 18 (+ 5) % Row 3 \SetRowColor{white} \seqsplit{LongUnaryOperator} & long \seqsplit{applyAsLong(long} operand) & Accepts a single long-valued operand and produces a long-valued result \tn % Row Count 23 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{4.0488 cm} x{5.7358 cm} x{7.0854 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Function}} \tn % Row 0 \SetRowColor{LightBackground} Function\textless{}T,R\textgreater{} & R apply(T t) & Represents a function that accepts one argument and produces a result (reference type) \tn % Row Count 6 (+ 6) % Row 1 \SetRowColor{white} DoubleFunction\textless{}R\textgreater{} & R apply(double value) & Accepts a double-valued argument and produces a result \tn % Row Count 10 (+ 4) % Row 2 \SetRowColor{LightBackground} IntFunction\textless{}R\textgreater{} & R apply(int value) & Accepts an int-valued argument and produces a result \tn % Row Count 14 (+ 4) % Row 3 \SetRowColor{white} LongFunction\textless{}R\textgreater{} & R apply(long value) & Accepts a long-valued argument and produces a result \tn % Row Count 18 (+ 4) % Row 4 \SetRowColor{LightBackground} \seqsplit{DoubleToIntFunction} & int \seqsplit{applyAsInt(double} value) & Accepts a double-valued argument and produces an int-valued result \tn % Row Count 23 (+ 5) % Row 5 \SetRowColor{white} \seqsplit{DoubleToLongFunction} & long \seqsplit{applyAsLong(double} value) & Accepts a double-valued argument and produces a long-valued result \tn % Row Count 28 (+ 5) % Row 6 \SetRowColor{LightBackground} \seqsplit{IntToDoubleFunction} & double \seqsplit{applyAsDouble(int} value) & Accepts an int-valued argument and produces a double-valued result \tn % Row Count 33 (+ 5) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{4.0488 cm} x{5.7358 cm} x{7.0854 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Function (cont)}} \tn % Row 7 \SetRowColor{LightBackground} \seqsplit{IntToLongFunction} & long \seqsplit{applyAsLong(int} value) & Accepts an int-valued argument and produces a long-valued result \tn % Row Count 4 (+ 4) % Row 8 \SetRowColor{white} \seqsplit{LongToIntFunction} & int \seqsplit{applyAsInt(long} value) & Accepts a long-valued argument and produces an int-valued result \tn % Row Count 8 (+ 4) % Row 9 \SetRowColor{LightBackground} \seqsplit{LongToDoubleFunction} & double \seqsplit{applyAsDouble(long} value) & Accepts a long-valued argument and produces a double-valued result. \tn % Row Count 13 (+ 5) % Row 10 \SetRowColor{white} ToDoubleFunction\textless{}T\textgreater{} & double \seqsplit{applyAsDouble(T} value) & Accepts a reference type and produces an int-valued result \tn % Row Count 17 (+ 4) % Row 11 \SetRowColor{LightBackground} ToIntFunction\textless{}T\textgreater{} & int applyAsInt(T value) & Accepts a reference type and produces an int-valued result \tn % Row Count 21 (+ 4) % Row 12 \SetRowColor{white} ToLongFunction\textless{}T\textgreater{} & long \seqsplit{applyAsLong(T} value) & Accepts a reference type and produces a long-valued result. \tn % Row Count 25 (+ 4) % Row 13 \SetRowColor{LightBackground} BiFunction\textless{}T,U,R\textgreater{} & R apply(T t, U u) & Represents a function that accepts two arguments and produces a result (reference type) \tn % Row Count 31 (+ 6) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{4.0488 cm} x{5.7358 cm} x{7.0854 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Function (cont)}} \tn % Row 14 \SetRowColor{LightBackground} ToDoubleBiFunction\textless{}T,U\textgreater{} & double \seqsplit{applyAsDouble(T} t, U u) & Accepts two reference type arguments and produces a double-valued result \tn % Row Count 5 (+ 5) % Row 15 \SetRowColor{white} ToIntBiFunction\textless{}T,U\textgreater{} & int applyAsInt(T t, U u) & Accepts two reference type arguments and produces an int-valued result \tn % Row Count 10 (+ 5) % Row 16 \SetRowColor{LightBackground} ToLongBiFunction\textless{}T,U\textgreater{} & long \seqsplit{applyAsLong(T} t, U u) & Accepts two reference type arguments and produces a long-valued result \tn % Row Count 15 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Custom Interface}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{@FunctionalInterface \newline interface \seqsplit{CustomFunctionalInterface} \{ \newline void display(); \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \end{document}