Warnings from last compilation.
Hi All,
The program correctly sorts the items in the String array.
.Warnings from last compilation are listed after the compile.
Note: C:\..\SortObjects.java uses unchecked or unsafe operations.
Note: Recompile with -XIint.unchecked for details <<<<
What is the meaning of these reported errors?
Your help is appreciated.
bH
import java.util.*;
public class SortObjects
{
public static void main(String s[])
{
String t[] = { "115R", "1125R", "147C", "37R", "57R",
"37C" }; // This is to simulate the user input
// The input is a String array. Make that an ArrayList:
List inputList = new ArrayList(Arrays.asList(t)); //
replace "t" by "s" for using the command line arguments
List l = sort(inputList);
System.out.println("\nStrings sorted List ...");
for(int i = 0; i < l.size(); i++)
System.out.println((String)l.get(i));
}
public static List sort(List list) {
Collections.sort(list, new Comparator() {
public int compare(Object o1, Object o2) {
String s1 = (String)o1;
String s2 = (String)o2;
String integer1[] = s1.split("[^0-9]"); //
<<<<< changed
String integer2[] = s2.split("[^0-9]"); //
<<<<< changed
String chars1[] = s1.split("[0-9]+"); //
<<<<< changed
String chars2[] = s2.split("[0-9]+"); //
<<<<< changed
Integer i1 = new
Integer( Integer.parseInt(integer1[0]) );
Integer i2 = new
Integer( Integer.parseInt(integer2[0]) );
if (i1.equals(i2))
return chars1[1].compareTo(chars2[1]);
else
return i1.compareTo(i2);
}
});
return list;
}
}