Hello I have implemented this basic program which should sort out the strings that are inserted however it somehow is failing to insert the strings . For example if I implement : testsort t = new testsort(); t.i("abc"); t.i("aab"); Can anybody see the error and help me fix this error please ? Thank you Here is the code : public class testsort { private int length; String[] data; public testsort() { length = 0; } public void i(String value) { data[length] = value; SetSorted(data); length++; } public void SetSorted(String data[]) { for(int i = data.length-1; i >= 0; i--) { for(int j = 0; j < i; j++) { if(data[j].compareTo(data[j + 1]) > -1) { String temp = data[j]; data[j] = data[j + 1]; data[j + 1] = temp; } } } for(int i = 0; i < data.length; i++) { System.out.print(data[i] +" "); } } }
data
testsort
data[length] = value
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)