Need help with Java for sorting by alphabetic order.

User Generated

Spunaybpb

Programming

Description

Collections.sort(name); did not work.

import java.util.ArrayList;

import java.util.Scanner;

import java.io.*;

public class Main {

 static ArrayList<String> name = new ArrayList<String>();

-

-

-

-

 public static void SortByName(){

    System.out.println("================================================");

    for ( int i = 0 ; i < name.size(); ++ i ){

      System.out.println("name: "+ name.get(i));}

      System.out.println("================================================");    

  } 

User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Explanation & Answer

Thank you for the opportunity to help you with your question!

The class was not closed  and the incremental value may have issues 

public static void SortByName(){

    System.out.println("================================================");

    for ( int i = 0 ; i < name.size(); i++){

      System.out.println("name: "+ name.get(i));}

      System.out.println("================================================");    

  } 

}

You close the class and you change the incremental sign

Please let me know if you need any clarification. I'm always happy to answer your questions.


Anonymous
Just what I needed…Fantastic!

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4

Related Tags