How to sort an ArrayList in Java with Example

In this tutorial we will learn how to sort an ArrayList in java. We will sort the String ArrayList and Integer ArrayList.

Read Also :  How to Reverse ArrayList in Java with Example

1. Program for Sorting String ArrayList

Here we are sorting the ArrayList of String type. We will use the Collections.sort(list) method.  In this case the output list will be sorted alphabetically.

19 Different Number Pattern Programs in Java

Java programs to print the numbers or any different pattern is one of the easiest ways to kick off your coding skills in java. In this post I have taken some different number pattern programs in java and tried to solve them . Please add more pattern and their code in the comment sections.


Pattern programs in java : Pattern 1

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7

import java.util.Scanner;
 
public class MainClass
{
    public static void main(String[] args) 
    {
        Scanner sc = new Scanner(System.in);
         
        //Taking rows value from the user
         
        System.out.println("How many rows you want in this pattern?");
         
        int rows = sc.nextInt();
         
        System.out.println("Here is your pattern....!!!");
         
        for (int i = 1; i <= rows; i++) 
        {
            for (int j = 1; j <= i; j++)
            {
                System.out.print(j+" ");
            }
             
            System.out.println();
        }
         
        //Close the resources
         
        sc.close();
    }
}