java.util.Collections.max()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(227)

本文整理了Java中java.util.Collections.max()方法的一些代码示例,展示了Collections.max()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Collections.max()方法的具体详情如下:
包路径:java.util.Collections
类名称:Collections
方法名:max

Collections.max介绍

[英]Searches the specified collection for the maximum element.
[中]在指定的集合中搜索最大元素。

代码示例

代码示例来源:origin: stackoverflow.com

import java.util.Arrays;
import java.util.Collections;

import org.apache.commons.lang.ArrayUtils;

public class MinMaxValue {

  public static void main(String[] args) {
    char[] a = {'3', '5', '1', '4', '2'};

    List b = Arrays.asList(ArrayUtils.toObject(a));

    System.out.println(Collections.min(b));
    System.out.println(Collections.max(b));
  }
}

代码示例来源:origin: apache/hive

protected double maxNdvForCorrelatedColumns(List<JoinLeafPredicateInfo> peLst,
ImmutableMap<Integer, Double> colStatMap) {
 int noOfPE = peLst.size();
 List<Double> ndvs = new ArrayList<Double>(noOfPE);
 for (int i = 0; i < noOfPE; i++) {
  ndvs.add(getMaxNDVForJoinSelectivity(peLst.get(i), colStatMap));
 }
 return Collections.max(ndvs);
}

代码示例来源:origin: stackoverflow.com

public class NewClass4 {
  public static void main(String[] args)
  {
    HashMap<Integer,Integer>map=new HashMap<Integer, Integer>();
    map.put(1, 50);
    map.put(2, 60);
    map.put(3, 30);
    map.put(4, 60);
    map.put(5, 60);
    int maxValueInMap=(Collections.max(map.values()));  // This will return max value in the Hashmap
    for (Entry<Integer, Integer> entry : map.entrySet()) {  // Itrate through hashmap
      if (entry.getValue()==maxValueInMap) {
        System.out.println(entry.getKey());     // Print the key with max value
      }
    }

  }
}

代码示例来源:origin: stackoverflow.com

public class MaxList {
  public static void main(String[] args) {
    List l = new ArrayList();
    l.add(1);
    l.add(2);
    l.add(3);
    l.add(4);
    l.add(5);
    System.out.println(Collections.max(l)); // 5
    System.out.println(Collections.min(l)); // 1
  }
}

代码示例来源:origin: googlesamples/android-Camera2Basic

if (option.getWidth() >= textureViewWidth &&
      option.getHeight() >= textureViewHeight) {
      bigEnough.add(option);
    } else {
      notBigEnough.add(option);
  return Collections.min(bigEnough, new CompareSizesByArea());
} else if (notBigEnough.size() > 0) {
  return Collections.max(notBigEnough, new CompareSizesByArea());
} else {
  Log.e(TAG, "Couldn't find any suitable preview size");

代码示例来源:origin: shopizer-ecommerce/shopizer

sizeList.add(pack.getShippingHeight());
  sizeList.add(pack.getShippingLength());
  sizeList.add(pack.getShippingWidth());
  Double maxSize = (Double)Collections.max(sizeList);
  if(size==null || maxSize.doubleValue() > size.doubleValue()) {
    size = maxSize.doubleValue();
System.out.println(inputParameters.toString());

代码示例来源:origin: org.apache.hadoop/hadoop-hdfs

RemoteEditLog bestLog = Collections.max(logGroup);
logs.add(bestLog);

代码示例来源:origin: jersey/jersey

public boolean contains(List<Integer> data) {
    if (Collections.min(data) < lower()
        || Collections.max(data) > upper()) {
      return false;
    } else {
      return true;
    }
  }
}

代码示例来源:origin: go-lang-plugin-org/go-lang-idea-plugin

placeholders.add(state.toPlaceholder());
  int maxArgNum = Collections.max(state.argNums);
  if (argNum < maxArgNum) {
   argNum = maxArgNum;

代码示例来源:origin: stackoverflow.com

List<Float> myList = new ArrayList<Float>();

System.out.print("Please enter your first temperature");
myList.add(scan.nextFloat());
System.out.print("Please enter your second temperature");
myList.add(scan.nextFloat());
System.out.print("Please enter your third temperature");
myList.add(scan.nextFloat());

System.out.println(Collections.min(myList));
System.out.println(Collections.max(myList));

代码示例来源:origin: yahoo/egads

/**
 * Creates a histogram of the provided data.
 * 
 * @param data list of observations
 * @param breaks number of breaks in the histogram
 * @return List of integer values size of the breaks
 */
public static List<Integer> getHistogram(List<Double> data, int breaks) {
  if (data.isEmpty()) {
    return Collections.emptyList();
  }
  List<Integer> ret = new ArrayList<Integer>(breaks);
  for (int i = 0; i < breaks; i++) {
    ret.add(0);
  }
  double min = Collections.min(data);
  double range = Collections.max(data) - min + 1;
  double step = range / breaks;
  for (double point : data) {
    // Math.min necessary because rounding error -> AIOOBE
    int index = Math.min((int) ((point - min) / step), breaks - 1);
    ret.set(index, ret.get(index) + 1);
  }
  return ret;
}

代码示例来源:origin: stackoverflow.com

int startFrom = 2; // configurable number
 List<Integer> intList = Arrays.asList(1,2,1,3,2,1,4);
 List<Integer> sortedList =  new ArrayList<>();
 for (int i = 0; i < intList.size(); i++) {
   if(i < startFrom){
     sortedList.add(null);
     continue;
   }
   ArrayList<Integer> list = new ArrayList<Integer>(intList.subList(i -startFrom, i+1));
   sortedList.add(Collections.max(list));
 }
 System.out.println(sortedList);

代码示例来源:origin: stackoverflow.com

import java.util.*;

public class Main {

  public static Character[] convert(char[] chars) {
    Character[] copy = new Character[chars.length];
    for(int i = 0; i < copy.length; i++) {
      copy[i] = Character.valueOf(chars[i]);
    }
    return copy;
  }

  public static void main(String[] args) {
    char[] a = {'3', '5', '1', '4', '2'};
    Character[] b = convert(a);
    System.out.println(Collections.max(Arrays.asList(b)));
  }
}

代码示例来源:origin: stackoverflow.com

List<Integer> list = Arrays.asList(100,2,3,4,5,6,7,67,2,32);
 int min = Collections.min(list);
 int max = Collections.max(list);
 System.out.println(min);
 System.out.println(max);

代码示例来源:origin: apache/kylin

private void setupMapper(CubeSegment cubeSeg) throws IOException {
  // set the segment's offset info to job conf
  Map<Integer, Long> offsetStart = cubeSeg.getSourcePartitionOffsetStart();
  Map<Integer, Long> offsetEnd = cubeSeg.getSourcePartitionOffsetEnd();
  Integer minPartition = Collections.min(offsetStart.keySet());
  Integer maxPartition = Collections.max(offsetStart.keySet());
  job.getConfiguration().set(CONFIG_KAFKA_PARITION_MIN, minPartition.toString());
  job.getConfiguration().set(CONFIG_KAFKA_PARITION_MAX, maxPartition.toString());
  for(Integer partition: offsetStart.keySet()) {
    job.getConfiguration().set(CONFIG_KAFKA_PARITION_START + partition, offsetStart.get(partition).toString());
    job.getConfiguration().set(CONFIG_KAFKA_PARITION_END + partition, offsetEnd.get(partition).toString());
  }
  job.setMapperClass(KafkaFlatTableMapper.class);
  job.setInputFormatClass(KafkaInputFormat.class);
  job.setOutputKeyClass(BytesWritable.class);
  job.setOutputValueClass(Text.class);
  job.setOutputFormatClass(SequenceFileOutputFormat.class);
  job.setNumReduceTasks(0);
}

代码示例来源:origin: nickbutcher/plaid

@Override
public void onDrawerOpened(View drawerView) {
  // scroll to the new item(s) and highlight them
  List<Integer> filterPositions = new ArrayList<>(sources.length);
  for (Source source : sources) {
    if (source != null) {
      filterPositions.add(filtersAdapter.getFilterPosition(source));
    }
  }
  int scrollTo = Collections.max(filterPositions);
  filtersList.smoothScrollToPosition(scrollTo);
  for (int position : filterPositions) {
    filtersAdapter.highlightFilter(position);
  }
  filtersList.setOnTouchListener(filtersTouch);
}

代码示例来源:origin: stackoverflow.com

List<Integer> list = new ArrayList<>();
   List<String> stringList = new ArrayList<>();
   // Populate the lists
   for(int i=0; i<=10; ++i){
     list.add(i);
     String newString = "String " + i;
     stringList.add(newString);
   }
   // add another negative value to the integer list
   list.add(-1939);
   // Print the min value from integer list and max value form the string list.
   System.out.println("Max value: " + Collections.min(list));
   System.out.println("Max value: " + Collections.max(stringList));

代码示例来源:origin: yahoo/egads

/**
 * Same as <code>getHistogram</code> but operates on <code>BigIntegers</code>.
 */
public static List<Integer> getHistogramBigInt(List<BigInteger> data, int breaks) {
  if (data.isEmpty()) {
    return Collections.emptyList();
  }
  List<Integer> ret = new ArrayList<Integer>(breaks);
  for (int i = 0; i < breaks; i++) {
    ret.add(0);
  }
  BigInteger min = Collections.min(data);
  BigInteger max = Collections.max(data);
  BigInteger range = max.subtract(min).add(BigInteger.valueOf(1));
  BigInteger step = range.divide(BigInteger.valueOf(breaks));
  if (step.equals(BigInteger.ZERO)) {
    return Collections.emptyList(); // too small
  }
  for (BigInteger point : data) {
    int index = point.subtract(min).divide(step).intValue();
    // Math.min necessary because rounding error -> AIOOBE
    index = Math.min(index, breaks - 1);
    ret.set(index, ret.get(index) + 1);
  }
  return ret;
}

代码示例来源:origin: stackoverflow.com

public static void main(String[] args) {
  Scanner scanner = new Scanner(System.in);
  List<Integer> list = new ArrayList<>();
  while (list.size() < 10 && scanner.hasNext()) {
    if (scanner.hasNextInt()) {
      list.add(scanner.nextInt());
    } else {
      scanner.next();
    }
  }
  Integer max = Collections.max(list);
  System.out.println(max);
}

代码示例来源:origin: stackoverflow.com

ArrayList<String> dirNo = new ArrayList<String>();
 dirNo.add("1");
 dirNo.add("2");
 dirNo.add("3");
 dirNo.add("4");
 dirNo.add("5");
 dirNo.add("6");
 dirNo.add("7");
 dirNo.add("8");
 dirNo.add("9");
 dirNo.add("10");
 dirNo.add("11");
 Comparator<String> cmp = new Comparator<String>() {
   @Override
   public int compare(String o1, String o2) {
     return Integer.valueOf(o1).compareTo(Integer.valueOf(o2));
   }
 };
 System.out.println("max : " + Collections.max(dirNo, cmp));

相关文章

Collections类方法