I have few strings whom I have to compare and the print the smallest,For eg:
A0< A1
A12< A22
A< B
12<23
a12< a21
Note:The string could be only number or only alphabet or can be mixture of both we have to compare it and print the smallest one first. My procedure:I checked the first character of string by "charAt " if its a letter I used compare to function if its a number I used IntParse method. But I could not figure out how to compare alphanumerical string like A12 < A21.
if ((assignment.getAssigncode()[i]).matches("[a-zA-Z]") &&
((assignment.getAssigncode()[j]).matches("[a-zA-Z]"))) {
if ((assignment.getAssigncode()[i]).compareTo((assignment.getAssigncode()[j])) > 0) {
swap();
} else {
if (Integer.parseInt((assignment.getAssigncode()[i])) >
Integer.parseInt((assignment.getAssigncode()[j]))) {
swap();
}
}
}