Computer Science, asked by SassyBean, 11 months ago

In Java, how can you sort the letters in each string of a string arrayList alphabetically?
For example:
Unsorted (candy, tacos, pizza)
Sorted ( acdny, acost, aipzz)

Answers

Answered by ranjeet2692
0

Input: Unsorted ArrayList: [Geeks, For, ForGeeks, GeeksForGeeks, A computer portal]

Output: Sorted ArrayList: [A computer portal, For, ForGeeks, Geeks, GeeksForGeeks]

// Java program to demonstrate

// How to sort ArrayList in ascending order

  

import java.util.*;

  

public class GFG {

    public static void main(String args[])

    {

  

        // Get the ArrayList

        ArrayList<String>

            list = new ArrayList<String>();

  

        // Populate the ArrayList

        list.add("Geeks");

        list.add("For");

        list.add("ForGeeks");

        list.add("GeeksForGeeks");

        list.add("A computer portal");

  

        // Print the unsorted ArrayList

        System.out.println("Unsorted ArrayList: "

                           + list);

  

        // Sorting ArrayList in ascending Order

        // using Collection.sort() method

        Collections.sort(list);

  

        // Print the sorted ArrayList

        System.out.println("Sorted ArrayList "

                           + "in Ascending order

Similar questions