比较JSONObjects的乘法

时间:2014-09-24 23:05:40

标签: android compare arrays

所以,我现在已经有了一些java值的集合,你可以看到

我有两个整数键(让我们说为tipO的值为1,2且id的值为3和4的例子)我想对结果进行排序他们的乘法:

这样的事情:

valA = a.get(KEY_ONE)* a.get(KEY_TWO); valB = b.get(KEY_ONE)* b.get(KEY_TWO);

然后比较它们。

我该怎么做?

这是我此时的代码。

Collections.sort( jsonValues, new Comparator<JSONObject>() {

            private static final String KEY_ONE = "tipo";
            private static final String Key_TWO = "id";

            @Override
            public int compare(JSONObject a, JSONObject b) {
                String valA = new String();
                String valB = new String();

                try {

                    valA = (String) a.get(KEY_ONE.toString());
                    valB = (String) b.get(KEY_ONE.toString());

                } 
                catch (JSONException e) {
                    //do something
                }

                return valA.compareTo(valB);

            }
        });

        for (int i = 0; i < jsonArray.length(); i++) {
            sortedJsonArray.put(jsonValues.get(i));
        }


        tvJson.setText(sortedJsonArray.toString());


    }
  }  

提前致谢!

0 个答案:

没有答案
相关问题