Home > Back-end >  Ignore case sorting characters
Ignore case sorting characters

Time:09-20

//import need package
Import the Java. Util. Collections;
Import the Java. Util. LinkedList;
import java.util.Scanner;

Public class WordSortAaToZz {
Public static void main (String [] args) {
Scanner in=new Scanner(System.in);
While (in) hasNext ()) {
String String=in nextLine ();
LinkedList List=new LinkedList<> (a);
Char [] cs=strig. ToCharArray ();
for(int i=0; i If ((cs [I] & gt;='a' & amp; & Cs [I] <='z') | | (cs [I] & gt;='A' & amp; & Cs [I] <)='z') {
System. The out. Print (list. Get (j));
j++;
} else {
System. The out. Print (cs) [I];
}
}
}
System.out.println();
}
}
}

CodePudding user response:

//the List sorted ignore case
Public List SortListIgnoreCase (List The list); {
The Collections. The sort (list, new Comparator () {
@ Override
Public int the compare (String s1, String s2) {
Return to s1.com pareToIgnoreCase (s2);
}
});
return list;
}

CodePudding user response:

You can try this:
 
String [] array={" b ", "A", "D", "c"};
Arrays. Sort (array, String. CASE_INSENSITIVE_ORDER);
System. The out. Println (EntityUtil. ToJson (array));


The console print:
 
[" A ", "b", "c", "D"]

CodePudding user response:

refer to the second floor of snow crystal reply:
you can try this:
 
String [] array={" b ", "A", "D", "c"};
Arrays. Sort (array, String. CASE_INSENSITIVE_ORDER);
System. The out. Println (EntityUtil. ToJson (array));


The console print:
 
[" A ", "b", "c", "D"]
works
  • Related