Java tutorial
//package com.java2s; import java.util.ArrayList; import java.util.HashSet; public class Main { public static void getTop(float[] array, ArrayList<Integer> rankList, int i) { rankList.clear(); int index = 0; HashSet<Integer> scanned = new HashSet<Integer>(); float max = Float.MIN_VALUE; for (int m = 0; m < i && m < array.length; m++) { boolean flag = false; max = Float.MIN_VALUE; for (int no = 0; no < array.length; no++) { if (!scanned.contains(no) && array[no] >= max) { index = no; max = array[no]; flag = true; } } if (flag) { // found value scanned.add(index); rankList.add(index); // rankProbs.add(array[index]); } // System.out.println(m + "\t" + index); } } public static void getTop(float[] array, ArrayList<Integer> rankList, ArrayList<Float> rankProbs, int i) { // clear rankList.clear(); rankProbs.clear(); // int index = 0; HashSet<Integer> scanned = new HashSet<Integer>(); float max = Float.MIN_VALUE; for (int m = 0; m < i && m < array.length; m++) { boolean flag = false; max = Float.MIN_VALUE; for (int no = 0; no < array.length; no++) { if (array[no] >= max && !scanned.contains(no)) { index = no; max = array[no]; flag = true; } } if (flag) { // found value scanned.add(index); rankList.add(index); rankProbs.add(array[index]); } // System.out.println(m + "\t" + index); } } }