Write a java program to arrange strings in alphabetical order

Write a java program to arrange strings in alphabetical order. Sorting names in alphabetical order with a Java program. Enter the array’s size, then all of the names in the array. We can now quickly arrange names in alphabetical order using the compareTo operator.The Java Program to Sort Names in Alphabetical Order source code is available here.

import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
int n;
String temp;
Scanner s = new Scanner(System.in);
System.out.print("Enter number of name you want to enter");
n = s.nextInt();
String names[] = new String[n];
Scanner s1 = new Scanner(System.in);
System.out.println("Enter all the name");
for(int i = 0; i < n; i++)
{
names[i] = s1.nextLine();
}
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
if (names[i].compareTo(names[j])>0)
{
temp = names[i];
names[i] = names[j];
names[j] = temp;
}
}
}
System.out.print("Names in sorted Order");
for (int i = 0; i < n - 1; i++)
{
System.out.print(names[i] + ",");
}
System.out.print(names[n - 1]);
}
}

Enter number of name you want to enter 3
Enter all the name
apple
microsoft
inlarn
Names in sorted Orderapple,inlarn,microsoft