can anyone help me ? i have an assignment about sorting alphabetically. i tried to search information on google, i found the codes, but i just cant understand. heres what i dont understand. please help
public class Alphasortingbubble { public static void main(String[ ] args) { String[ ] names = {"joe", "slim", "ed", "george"}; sortStringBubble (names); for ( int k = 0; k < 4; k++ ) System.out.println( names [ k ] ); } public static void sortStringBubble( String names [ ] ) { boolean flag = true; // will determine when the sort is finished String temp; while ( flag ) { flag = false; // i dont understand why this is false for (int i = 0; i < names.length - 1; i++ ) { if ( names [ i ].compareTo( names [ i+1 ] ) > 0 ) { // ascending sort /*i print this one and the result is number. i dont understand where the numbers come from System.out.println( "nama : " + names [ i ].compareTo( names [ i+1 ] )); */ temp = names [ i ]; names [ i ] = names [ i+1]; // swapping names [ i+1] = temp; flag = true; //why this is true } } } } }