-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringSorting.java
More file actions
22 lines (18 loc) · 558 Bytes
/
StringSorting.java
File metadata and controls
22 lines (18 loc) · 558 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package ch18.stringprocessing;
public class StringSorting {
public static void main(String[] args) {
String[] strArray = { "dan", "ann", "linda", "ann" };
for (int i = 0; i < strArray.length; i++) {
for (int j = i + 1; j < strArray.length; j++) {
if (strArray[i].compareToIgnoreCase(strArray[j]) > 0) {
String temp = strArray[j];
strArray[j] = strArray[i];
strArray[i] = temp;
}
} // end of inner for
} // end of outer for
for (int i = 0; i < strArray.length; i++) {
System.out.print(strArray[i] + " ");
}
}
}