Skip to content

Instantly share code, notes, and snippets.

@mkdika
Created November 6, 2016 06:25
Show Gist options
  • Save mkdika/1156ae90818234ed7854f9e3624e302e to your computer and use it in GitHub Desktop.
Save mkdika/1156ae90818234ed7854f9e3624e302e to your computer and use it in GitHub Desktop.
import java.util.Arrays;
public class BubbleSortString {
public static void BubbleSort(String[] arrs) {
String temp;
System.out.print("Before Sort: ");
System.out.println(Arrays.toString(arrs));
for (int i = 0; i < arrs.length - 1; i++) {
for (int j = 0; j < arrs.length - 1; j++) {
if (arrs[j].compareTo(arrs[j+1])>0 ) {
temp = arrs[j];
arrs[j] = arrs[j + 1];
arrs[j + 1] = temp;
}
}
}
System.out.print("After Sort : ");
System.out.println(Arrays.toString(arrs));
}
public static void main(String arg[]) {
String[] data = {"Jack Man","Budi Man","Andy Gunawan","Denny Tejo",
"Sofyan","Fendy Agus"};
BubbleSort(data);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment