Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/192.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我正在尝试对字符串数组的列表进行排序。我使用了Collection.sort方法,但答案是错误的 Collections.sort(stringList,新的比较器(){ 公共整数比较(字符串[]字符串,字符串[]其他字符串){ 返回(字符串[1]。比较到(其他字符串[1]);_Java_Android - Fatal编程技术网

Java 我正在尝试对字符串数组的列表进行排序。我使用了Collection.sort方法,但答案是错误的 Collections.sort(stringList,新的比较器(){ 公共整数比较(字符串[]字符串,字符串[]其他字符串){ 返回(字符串[1]。比较到(其他字符串[1]);

Java 我正在尝试对字符串数组的列表进行排序。我使用了Collection.sort方法,但答案是错误的 Collections.sort(stringList,新的比较器(){ 公共整数比较(字符串[]字符串,字符串[]其他字符串){ 返回(字符串[1]。比较到(其他字符串[1]);,java,android,Java,Android,我写了这段代码,但答案是 一, 11 12 19 2. 3. 4. 5. 6. 七, 有谁能告诉我如何解决这个问题吗?这没有错。这是字符串的默认顺序-字典顺序。 如果要按数字表示对字符串进行排序,请先将其转换为整数 例如: Collections.sort(stringList, new Comparator < String[] > () { public int compare(String[] strings, String[] otherStrings) {

我写了这段代码,但答案是

一, 11 12 19 2. 3. 4. 5. 6. 七,


有谁能告诉我如何解决这个问题吗?这没有错。这是字符串的默认顺序-字典顺序。 如果要按数字表示对字符串进行排序,请先将其转换为整数

例如:

Collections.sort(stringList, new Comparator < String[] > () {
    public int compare(String[] strings, String[] otherStrings) {
        return  (strings[1].compareTo(otherStrings[1]));
Collections.sort(stringList,新的比较器(){
公共整数比较(字符串[]字符串,字符串[]其他字符串){
返回Integer.valueOf(字符串[1]).compareTo(Integer.valueOf(其他字符串[1]));
}
});

这没有错。这是字符串的默认顺序-字典顺序。 如果要按数字表示对字符串进行排序,请先将其转换为整数

例如:

Collections.sort(stringList, new Comparator < String[] > () {
    public int compare(String[] strings, String[] otherStrings) {
        return  (strings[1].compareTo(otherStrings[1]));
Collections.sort(stringList,新的比较器(){
公共整数比较(字符串[]字符串,字符串[]其他字符串){
返回Integer.valueOf(字符串[1]).compareTo(Integer.valueOf(其他字符串[1]));
}
});

使用自定义比较器

Collections.sort(stringList, new Comparator<String[]> () {
    public int compare(String[] strings, String[] otherStrings) {
        return Integer.valueOf(strings[1]).compareTo(Integer.valueOf(otherStrings[1]));
    }
});
公共类CustomComparator实现Comparator{
@凌驾
公共整数比较(字符串lhs、字符串rhs){
int l=整数.parseInt(lhs);
int r=Integer.parseInt(rhs);

返回l使用自定义比较器

Collections.sort(stringList, new Comparator<String[]> () {
    public int compare(String[] strings, String[] otherStrings) {
        return Integer.valueOf(strings[1]).compareTo(Integer.valueOf(otherStrings[1]));
    }
});
公共类CustomComparator实现Comparator{
@凌驾
公共整数比较(字符串lhs、字符串rhs){
int l=整数.parseInt(lhs);
int r=Integer.parseInt(rhs);

return ldo你有数组列表吗???我有列表a;也许我不应该,但我不禁想知道-为什么你要比较字符串数组中的第二个元素?你有数组列表吗???我有列表a;也许我不应该,但我不禁想知道-为什么你要比较字符串数组中的第二个元素?