java如何对参数键值对排序

如果按你这个例子来说 那个url是由容器自己解析的根本用不着自己搞

Ⅱ java如何对map集合进行值valuie的倒排序,出现值相同的再健key的倒排序,最后keyvalue组合输出

public static void main(String[] args) {
Map<Integer,Integer> map = new HashMap<Integer,Integer>();
map.put(1, 11);
map.put(2, 44);
map.put(3, 55);
map.put(4, 21);
map.put(5, 33);
map.put(6, 11);
//这里将map.entrySet()转换成list
List<Map.Entry<Integer,Integer>> list = new ArrayList<Map.Entry<Integer,Integer>>(map.entrySet());
//然后通过比较器来实现排序
Collections.sort(list,new Comparator<Map.Entry<Integer,Integer>>() {
//升序排序
public int compare(Entry<Integer, Integer> o1,Entry<Integer, Integer> o2) {
return o1.getValue().compareTo(o2.getValue());
}

});

for(Map.Entry<Integer,Integer> mapping:list){
System.out.println(mapping.getKey()+":"+mapping.getValue());
}
}
这是根据value的值排序的,你也可以泛型成Map<String,String>一样的 希望能帮到你!

Ⅲ 在java里如何对一个map按key排序:Map<String, String[]>

使用map.entrySet()
不需要导入jar entrySet方法是Map自带的方法

有不懂的可以追问

Ⅳ 如何对Map进行字典排序Java

//根据 Map的key进行字典排序内容
Map<String, String> parameterMap = new HashMap<String, String>();
List<Map.Entry<String,String>> list = new ArrayList<Map.Entry<String,String>>(parameterMap.entrySet());
Collections.sort(list,new Comparator<Map.Entry<String,String>>() {
//升序排序
public int compare(Entry<String, String> o1,
Entry<String, String> o2) {
return o1.getKey().compareTo(o2.getKey());
}

});

Ⅳ java排序,效率高的是哪种排序方法

和所有其他语言是一样的。应该还是快速排序效率最高。

public static void bubbleSort(int a[]) {
int len = a.length;
for (int i = 0; i < len - 1; i++) {
for (int j = 0; j < len - 1 - i; j++) {
if (a[j] > a[j + 1]) {
int temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
}
}
}
public static void selectSort(int a[]) {
int temp = 0;
int len = a.length;
for (int i = 0; i < len - 1; i++) {
int min = a[i];
int index = i;
for (int j = i + 1; j < len; j++) {
if (min > a[j]) {
min = a[j];
index = j;
}
}
temp = a[i];
a[i] = a[index];
a[index] = temp;
}
}
public static void insertSort(int a[]) {
int len = a.length;
for (int i = 1; i < len; i++) {
int temp = a[i];// 待插入的值
int index = i;// 待插入的位置
while (index > 0 && a[index - 1] > temp) {
a[index] = a[index - 1];// 待插入的位置重新赋更大的值
index--;// 位置往前移
}
a[index] = temp;
}
}
public static int partition(int a[], int low, int height) {
int key = a[low];
while (low < height) {
while (low < height && a[height] >= key)
height--;
a[low] = a[height];
while (low < height && a[low] <= key)
low++;
a[height] = a[low];
}
a[low] = key;
return low;
}
public static void quickSort(int a[], int low, int height) {
if (low < height) {
int result = partition(a, low, height);
quickSort(a, low, result - 1);
quickSort(a, result + 1, height);
}
}
测试结果
------------------------------------------
测试数据10000
冒泡排序:120ms
选择排序:32ms
插入排序:20ms
快速排序:7ms
------------------------------------------
测试数据100000
冒泡排序:13098ms
选择排序:2334ms
插入排序:1264ms
快速排序:23ms
效率差距很大啊!!!!

Ⅵ Java怎么实现HashMap或TreeMap以key值进行排序

HashMap本身是hash散列,做不到你说的排序。
TreeMap可以,是二叉树实现,自己实现一个Comparator。

Ⅶ json对象排序把key中的value值排序

Arrays.sort() java中的排序方法 如果是对象的话可以自己写比较器compare()自己定义比较对象中的某个属性

Ⅷ java里,想对hashmap里的key进行排序

chNNN -> NNN -> Integer.parseInt(NNN)
"ch10" -> "10" -> Integer.parseInt("10") -> 10
--------
Yes, you are right, but not too slow/difficult:

import java.util.*;

public class Tmp {
public static void main(String[] args) {
Map<String, Object> result = new HashMap<String, Object>();
result.put("ch1", "ch 1");
result.put("ch111", "ch 111");
result.put("ch11", "ch 11");
result.put("ch2", "ch 2");
result.put("ch13", "ch 13");
Object[] keys=result.keySet().toArray();
Comparator<Object> c = new Comparator<Object>(){
@Override
public int compare(Object o1, Object o2) {
//TODO: add argument check yourself
int a1 = Integer.parseInt(((String)o1).substring(2));
int a2 = Integer.parseInt(((String)o2).substring(2));
if(a1>a2)return 1;
if(a1==a2)return 0;
else return -1;
}
};
Arrays.sort(keys, c);
for(Object s:keys){
System.out.println(s +"=>"+result.get(s));
}
}
}

Ⅸ Java中如何对Map的value或者key排序

Object
obj
=
new
Object();
obj
=
map.get("key");
map是Map的那个对象,“key”是表示key的那个值,一般是个字符串