Home » Java » How to sort collection in java without using Collection.sort();-Exceptionshub

How to sort collection in java without using Collection.sort();-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

So my teacher gave me this starter code to work on but I don’t know how to do the one where I have to sort the names in alphabetical order without using Collection.sort();

Any and all help is appreciated.
Thank you so much in advance!

Here is the code:

  public static ArrayList<String> sortMethod(ArrayList<String> list)
  {
      //SortMethod: Write a method that receives an ArrayList of Strings
      //and sorts them into alphabetical order.
      //DO NOT use Collection.sort!
      //return the sorted ArrayList

      THIS IS THE ONE I AM CONFUSED ABOUT

  }                   

    public static void main (String[] args)
    {
        Scanner reader = new Scanner(System.in);

        //test method 2
        names = sortMethod(names);
        System.out.println(names);

    }
}
How to&Answers: