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


Java Comparators.NullComparator方法代码示例

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


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

示例1: 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

示例2: 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.NullComparator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。