JSON数组去重,list数组对象进行去重

js对json数组去重
/*
 * JSON数组去重
 * @param: [array] json Array
 * @param: [string] 唯一的key名,根据此键名进行去重
 */
  uniqueArray:function (array, key){
    var result = [array[0]];
    for(var i = 1; i<array.length; i++){
    var item = array[i];
    var repeat = false;
    for (var j = 0; j < result.length; j++) {
      if (item[key] == result[j][key]) {
        repeat = true;
        break;
      }
    }
    if (!repeat) {
      result.push(item);
    }
  }
  return result;
  },

java对 list数组对象进行去重
 /**
     * 去重
     * 
     * @param orderList
     * @return
     * @author jqlin
     */
    private static List removeDuplicateOrder(List orderList) {
        Set set = new TreeSet(new Comparator() {
            @Override
            public int compare(PageData a, PageData b) {
                // 字符串则按照asicc码升序排列
                return  a.getString("var0").compareTo(b.getString("var0"));
            }
        });

        set.addAll(orderList);
        return new ArrayList(set);
    }

你可能感兴趣的:(java)