implement the bubble sort algorithm on the following arraylist

Solutions on MaxInterview for implement the bubble sort algorithm on the following arraylist by the best coders in the world

showing results for - "implement the bubble sort algorithm on the following arraylist"
Camilla
02 Feb 2020
1import java.util.ArrayList;
2
3public class Sort{
4    private static ArrayList<String> list = new ArrayList<String>();
5
6    public static ArrayList<String> sortByName(String [] input) {
7        String temp;
8        for (int i=0; i< input.length; i++){
9            for(int j= i; j< input.length-1; j++){
10                char first = input[i].charAt(0);
11                char sec = input[j +1].charAt(0);
12                 if (first < sec)  {
13                     temp = input[j +1];
14                     input[j +1] = input[i];        
15                     input[i] = temp;
16                 }
17             }
18            list.add(input[i]);
19         }
20
21        return list;
22    }
23
24    public static void main(String[] args) {
25        String string[] =  {"Ezen", "Allen" , "Wilker", "Kruden", "Crocket"};
26        bubbleSortByName(string);
27    }
28}