当前位置: 首页>>代码示例>>Java>>正文


Java Comparators类代码示例

本文整理汇总了Java中java.util.Comparators的典型用法代码示例。如果您正苦于以下问题:Java Comparators类的具体用法?Java Comparators怎么用?Java Comparators使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Comparators类属于java.util包,在下文中一共展示了Comparators类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: naturalOrder

import java.util.Comparators; //导入依赖的package包/类
/**
 * Returns a comparator that compares {@link Comparable} objects in natural
 * order.
 *
 * <p>The returned comparator is serializable and throws {@link
 * NullPointerException} when comparing {@code null}.
 *
 * @param  <T> the {@link Comparable} type of element to be compared
 * @return a comparator that imposes the <i>natural ordering</i> on {@code
 *         Comparable} objects.
 * @see Comparable
 * @since 1.8
 */
@SuppressWarnings("unchecked")
public static <T extends Comparable<? super T>> Comparator<T> naturalOrder() {
    return (Comparator<T>) Comparators.NaturalOrderComparator.INSTANCE;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:Comparator.java

示例2: nullsFirst

import java.util.Comparators; //导入依赖的package包/类
/**
 * Returns a null-friendly comparator that considers {@code null} to be
 * less than non-null. When both are {@code null}, they are considered
 * equal. If both are non-null, the specified {@code Comparator} is used
 * to determine the order. If the specified comparator is {@code null},
 * then the returned comparator considers all non-null values to be equal.
 *
 * <p>The returned comparator is serializable if the specified comparator
 * is serializable.
 *
 * @param  <T> the type of the elements to be compared
 * @param  comparator a {@code Comparator} for comparing non-null values
 * @return a comparator that considers {@code null} to be less than
 *         non-null, and compares non-null objects with the supplied
 *         {@code Comparator}.
 * @since 1.8
 */
public static <T> Comparator<T> nullsFirst(Comparator<? super T> comparator) {
    return new Comparators.NullComparator<>(true, comparator);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:21,代码来源:Comparator.java

示例3: nullsLast

import java.util.Comparators; //导入依赖的package包/类
/**
 * Returns a null-friendly comparator that considers {@code null} to be
 * greater than non-null. When both are {@code null}, they are considered
 * equal. If both are non-null, the specified {@code Comparator} is used
 * to determine the order. If the specified comparator is {@code null},
 * then the returned comparator considers all non-null values to be equal.
 *
 * <p>The returned comparator is serializable if the specified comparator
 * is serializable.
 *
 * @param  <T> the type of the elements to be compared
 * @param  comparator a {@code Comparator} for comparing non-null values
 * @return a comparator that considers {@code null} to be greater than
 *         non-null, and compares non-null objects with the supplied
 *         {@code Comparator}.
 * @since 1.8
 */
public static <T> Comparator<T> nullsLast(Comparator<? super T> comparator) {
    return new Comparators.NullComparator<>(false, comparator);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:21,代码来源:Comparator.java


注:本文中的java.util.Comparators类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。