Write a Java program to check if two strings are anagrams or not.

Here’s a Java program to check if two strings are anagrams or not:

import java.util.Arrays;
import java.util.Scanner;

public class Anagram {
    public static void main(String[] args) {
        String str1, str2;
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter the first string: ");
        str1 = scanner.nextLine();
        System.out.print("Enter the second string: ");
        str2 = scanner.nextLine();
        if (isAnagram(str1, str2)) {
            System.out.println(str1 + " and " + str2 + " are anagrams.");
        } else {
            System.out.println(str1 + " and " + str2 + " are not anagrams.");
        }
    }

    public static boolean isAnagram(String str1, String str2) {
        if (str1.length() != str2.length()) {
            return false;
        }
        char[] arr1 = str1.toCharArray();
        char[] arr2 = str2.toCharArray();
        Arrays.sort(arr1);
        Arrays.sort(arr2);
        return Arrays.equals(arr1, arr2);
    }
}

In this program, we first take user input for two strings. We then call the `isAnagram()` method to check if they are anagrams or not.

The `isAnagram()` method takes two string parameters `str1` and `str2` and returns a boolean value indicating whether they are anagrams or not. We first check if the length of the two strings is the same. If they are not, then they cannot be anagrams. We then convert the two strings to char arrays using the `toCharArray()` method and sort them using the `Arrays.sort()` method. We then use the `Arrays.equals()` method to compare the two sorted char arrays. If they are equal, then the two strings are anagrams.

At the end of the program, we print out a message indicating whether the two strings are anagrams or not.