Please provide an example how to sort ArrayList?
public static JSONArray sortJSONArrayAlphabetically(JSONArray jArray) throws JSONException {
if (jArray != null) {
// Sort:
ArrayList<String> arrayForSorting = new ArrayList<>();
for (int i = 0; i < jArray.length(); i++) {
arrayForSorting.add(jArray.get(i).toString());
}
Collections.sort(arrayForSorting);
// Prepare and send result:
JSONArray resultArray = new JSONArray();
for (int i = 0; i < arrayForSorting.size(); i++) {
resultArray.put(new JSONObject(arrayForSorting.get(i)));
}
return resultArray;
}
return null; // Return error.
}
this method fail
warning: [options] bootstrap class path not set in conjunction with -source 1.6 1 warning Init env executing with cn1env = ${cn1env} for ../../CodenameOne/GUIBuilder/src Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: Some input files use unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. Compile is forcing compliance to the supported API's/features for maximum device compatibility. This allows smaller code size and wider device support F:\data_kdp\programs\CodenameOne\ws_codenameone\forcesoscn1appclient_kdp\src\com\geotracksolutionsint\forcesos\utils\Utils.java:9006: error: no suitable method found for sort(ArrayList) Collections.sort(arrayForSorting); method Collections.<T#1>sort(List<T#1>) is not applicable (inference variable T#1 has incompatible bounds equality constraints: String upper bounds: Comparable<? super T#1>) method Collections.<T#2>sort(List<T#2>,Comparator<? super T#2>) is not applicable (cannot infer type-variable(s) T#2 (actual and formal argument lists differ in length)) where T#1,T#2 are type-variables: T#1 extends Comparable<? super T#1> declared in method <T#1>sort(List<T#1>) T#2 extends Object declared in method <T#2>sort(List<T#2>,Comparator<? super T#2>) Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: Some input files use unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details.