array to sort names in alphabetical order
just trying to complete a tutorial on constructing a basic array to sort names in alphabetical order and still cannot get it to work would be grateful for any help
package introtoarrays1;
public class IntroToArrays1 {
public static void main(String[] args) {
String [] name = new String[6];
String tempStr;
name[0]="Bob";
name[1]="Jenny";
name[2]="Charlie";
name[3]="Jerry";
name[4]="Roberta";
name[5]="Anita";
for(int t=0;t<name.length-1;t++){
for (int i = 0; i < name.length - 1; i++) {
if (name[i].compareTo(name[1 + 1]) > 0) {
tempStr = name[i];
name[i] = name[i + 1];
name[i + 1] = tempStr;
}
}
}
for(int i=0;i<name.length;i++){
System.out.println(name[i]);
}
}
}