null
1 package test; 2 3 import java.util.Collection; 4 import java.util.Iterator; 5 import java.util.TreeMap; 6 7 8 public class meituan { 9 10 public static void main(String[] args) { 11 12 int []a = {5,6,2,1}; 13 TreeMap<arrKey,index> tree = new TreeMap<arrKey,index>(); 14 15 for(int i=0;i<a.length-1;i++){ 16 for(int j=i+1;j<a.length;j++){ 17 tree.put(new arrKey(a[j]-a[i]), new index(i,j)); 18 } 19 } 20 Collection<index> col = tree.values(); 21 Iterator<index> it = col.iterator(); 22 System.out.println(tree.lastEntry().getValue().toString()); 23 } 24 25 } 26 27 class index{ 28 29 private int a; 30 private int b; 31 public index(int a, int b) { 32 super(); 33 this.a = a; 34 this.b = b; 35 } 36 @Override 37 public String toString() { 38 // TODO Auto-generated method stub 39 return "a为:"+a+" b为:"+b; 40 } 41 } 42 43 class arrKey implements Comparable{ 44 45 private int value; 46 47 public arrKey(int value) { 48 super(); 49 this.value = value; 50 } 51 52 @Override 53 public int compareTo(Object o) { 54 55 arrKey mKey = (arrKey)o; 56 57 if(this.value - mKey.value == 0){ 58 return -1; 59 }else{ 60 return (this.value - mKey.value); 61 } 62 } 63 }