public static Map<String, String> arraySameIndex(String[] array){
Map<String, String> map = new HashMap<String, String>();
for(int i = 0; i < array.length; i++){
String h = array[i];
boolean flag = false;
for (int j = 0; j < i; j++) {
if(array[j]==h){
flag = true;
}
}
if(!flag){
StringBuffer sb = new StringBuffer();
for (int j = 0; j < array.length; j++) {
if(h==array[j]){
sb.append(",").append(j);
}
}
sb.delete(0, 1).insert(0, "[").append("]");
String newKey = sb.toString().replace("[", "").replace("]", "");
String[] keyArray = newKey.split(",");
String indexMapKey = keyArray[0]+"_"+keyArray[keyArray.length-1];
System.out.println("开始下标:"+keyArray[0]+" 结束下标:"+keyArray[keyArray.length-1]);
map.put(indexMapKey, indexMapKey);
}
}
return map;
}
public static void main(String[] args) {
//获取连续相同元素114的下标,也就是3 - 4
String[] str = {"110","110","113","114","114"};
System.out.println(arraySameIndex(str));
}