java compare strings alphabetically

Solutions on MaxInterview for java compare strings alphabetically by the best coders in the world

showing results for - "java compare strings alphabetically"
Victoire
29 Oct 2016
1String a = "HYRE"; 
2String b = "AGNYG";  
3
4int compare = a.compareTo(b);  
5
6if (compare < 0) {  
7    //a is smaller
8}
9else if (compare > 0) {
10    //a is larger 
11}
12else {  
13    //a is equal to b
14} 
Lorenzo
25 Jan 2020
1Different 'Collation Strength' values give different sort results: 
2[Äbc, äbc, Àbc, àbc, Abc, abc, ABC] - Original Data
3[Äbc, äbc, Àbc, àbc, Abc, abc, ABC] Primary
4[Abc, abc, ABC, Àbc, àbc, Äbc, äbc] Secondary
5[abc, Abc, ABC, àbc, Àbc, äbc, Äbc] Tertiary
6
7Case kicks in only with Tertiary Collation Strength  : 
8[cache, CACHE, Cache] - Original Data
9[cache, CACHE, Cache] Primary
10[cache, CACHE, Cache] Secondary
11[cache, Cache, CACHE] Tertiary
12
13Accents kick in with Secondary Collation Strength.
14Compare with no accents present: 
15Collator sees them as the same : abc, ABC - Primary
16Collator sees them as the same : abc, ABC - Secondary
17Collator sees them as DIFFERENT: abc, ABC - Tertiary
18
19Compare with accents present: 
20Collator sees them as the same : abc, ÀBC - Primary
21Collator sees them as DIFFERENT: abc, ÀBC - Secondary
22Collator sees them as DIFFERENT: abc, ÀBC - Tertiary
23
queries leading to this page
how to compare strings alphabetically in javaalphabetically compare strings javacompare alphabetical order javahow to check if one string is alphabetically before another in javajava string sorting alphabeticallycompare string java alphabeticaljava sort strings alphabeticallyhow to use compareto to sort alphabetically in javajava compare strings alphabeticallysort java strings alphabeticallyhow to alphabetize strings in javacompare multiple strings and arrange alphabetically in javajava compare alphabetically stringsjava string comparison alphabetical ordercompare strings alphabetically javajava string order alphabeticallyjava compare strings alphabetically booleancompare two characters alphabetically javaorder strings alphabetically javacompare string alphabetical order javacompare two strings for alphabetical order javahow to sort two strings alphabetically in javahow to compare strings in java alphabeticallysort two strings alphabetically javajava sort string alphabeticallyhow to sort a string alphabetically in javahow to compare 2 strings alphabetically javacompare alphabetically javahow to compare two strings alphabetically in javasorting strings alphabetically using compareto 28 29 method in javahow to identify alphabetically greater string javacompare two string alphabetically javajava compare two strings alphabeticallyjava strings sort alphabeticallyjava string sort alphabeticallysee which string is higher alphabetically javajava compare char alphabeticallyjava arrange string alphabeticallycompare string alphabetically javacomparing two strings alphabetically javahow to sort strings alphabetically in javafunction comparing two strings alphabetically javacompare 2 string by alphabetically javacompare two strings in java alphabeticallyhow to code a string in java with alphabeticallycomparing word alphabetically javacompare string alphabetic in javajava comparator string alphabeticallyjava compareto alphabetical ordersort strings alphabetically in javaalphabetic comparisonhow to compare two strings in java alphabeticaljava sort two strings alphabeticallyjava check which string coes first albpabeticallycompare strings alphabetically method javacompare two strings java alphabetical orderjava comparator string alphabeticalcompare alphabet javacomparing words by alphabetical orderhow to know which string comes alphabetically first javajava compare string alphabeticallyalphabetical compare to string javahow to compare alphabetical order in javause compareto in java alphabetical orderjava comparator string alphabetical orderhow to compare names alphabetically javahow to compare more than two string in java alphabeticallyjava compareto strings alphabeticallyjava compare alphabetical order of stringsstring compare alphabetically javajava how to compare strings alphabeticallycompare 2 string alphabetically javacomparing alphabetical order javajava compare strings alphabetically case insensitivehow to compare letter alphabetically javacompare two strings alphabetically javahow to compare 2 strings in alphbet orderhow to compare two strings based on alphabetically in javajava order strings alphabeticallycompare two string in alphabetically javacompare strings java alphabeticallyhow to put strings in alphabetical order javajava compare string alphabetical orderjava code to compare strings alphabeticallyjava compare alphabeticallyjava compare strings alphabetically