Java Spliterator getComparator() MethodThe getComparator() method of Java Interface Spliterator is used to get a Comparator if the given Spliterator?s source is SORTED by a Comparator. It returns null if the source is SORTED in a natural order. Otherwise, if the source is not SORTED, throws IllegalStateException. SyntaxFollowing is the declaration of getComparator() method- ParameterThis method does not accept any parameter. ReturnThe getComparator() method would return a comparator or a null value if the elements were sorted in the natural order. ExceptionsIllegalStateException- This method has thrown an exception if the spliterator does not report a characteristic of SORTED. Compatibility VersionJava 1.8 and above Example 1Output: Exception in thread "main" java.lang.IllegalStateException at java.base/java.util.Spliterator.getComparator(Spliterator.java:465) at myPackage.InterfaceSpliteratorGetComparatorExample1.main(InterfaceSpliteratorGetComparatorExample1.java:16) Example 2Output: myPackage.InterfaceSpliteratorGetComparatorExample2$$Lambda$1/[email protected] [Test{str='one'}, Test{str='two'}] |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India