compare Summary Compares the Boolean object to another Boolean object. Usage public final Comparison compare(Boolean object) Returns A System.Comparison enumeration result representing whether the specified Boolean comparison object is less than, equal to, or greater than the current Boolean object. Parameters object The Boolean object to compare to. Description Compares the Boolean object to another Boolean object. Returns one of the following System.Comparison enumeration values: System.Comparison.LESS_THAN System.Comparison.EQUAL System.Comparison.GREATER_THAN Examples Basic Usage 12345import System; bool b = true;Comparison result = b.compare(true);Console.log(result == Comparison.EQUAL); Sorting 12345import System; bool[] arr = [ true, false, true, false ];arr.sort(); // 'System.Array<T>.sort' uses 'compare' to sort elementsConsole.log(arr.join(", ")); Custom Sort 1234567891011121314151617import System;import System.Assert; bool[] arr = [ true, false, true, false ];arr.sort(Comparison(bool a, bool b) { if (a < b) { return Comparison.LESS_THAN; } else if (a > b) { return Comparison.GREATER_THAN; } else { assert(a == b); return Comparison.EQUAL; }});Console.log(arr.join(", ")); Share HTML | BBCode | Direct Link