Takes a string array and searches for two words that are anagrams of each other Looking for some advice on whether or not this can be improved in terms of efficiency and speed, it would need to work on large data sets.

public class Anagrams {

    public static boolean isAnagram(String str1, String str2) {  
    String s1 = str1.replaceAll("\\s", "");  
    String s2 = str2.replaceAll("\\s", "");  
    boolean status = true;  
    if (s1.length() != s2.length()) {  
        status = false;  
    } else {  
        char[] ArrayS1 = s1.toLowerCase().toCharArray();  
        char[] ArrayS2 = s2.toLowerCase().toCharArray();  
        Arrays.sort(ArrayS1);  
        Arrays.sort(ArrayS2);  
        status = Arrays.equals(ArrayS1, ArrayS2);  
    }  
    if (status) {  
        return true; 
    } else {  
        return false; 
    }  
    }  


    public static String searchAnagram(String[] array)
    {

        String anagramsList = "";
        Arrays.sort(array, (str1, str2) -&gt; str1.length() - str2.length());
        for(int i=0;i&lt;(array.length -1); i++)
        {
            int j=0;
            while(array[i].length() == array[i+j].length())
            {

                if(isAnagram(array[i],array[i+j]))
                {
                    anagramsList += (array[i] + " " + array[i+j] + ", ");
                    System.out.println(array[i] + " " + array[i+j] + ", ");
                }
                j++;
            }

        }
        if(anagramsList == "")
        {
            anagramsList = "No anagrams foud";
        }
        return anagramsList;
    }

}
In isAnagram one should start local variables with a small letter (just a convention).
Do not use if-else to return a boolean.

public static boolean isAnagram(String str1, String str2) {
    String s1 = str1.replaceAll("\\s", "");
    String s2 = str2.replaceAll("\\s", "");
    boolean status = true;
    if (s1.length() != s2.length()) {
        status = false;
    } else {
        char[] arrayS1 = s1.toLowerCase().toCharArray();
        char[] arrayS2 = s2.toLowerCase().toCharArray();
        Arrays.sort(arrayS1);
        Arrays.sort(arrayS2);
        status = Arrays.equals(arrayS1, arrayS2);
    }
    return status;
}


However if you think of an anagram as a form of sorted string, one could introduce either a type Anagram, or - here - a function deriving such a sorted string: here canonicalForm.

public static boolean isAnagram2(String str1, String str2) {
    return canonicalForm(str1).equals(canonicalForm(str2));
}

public static String canonicalForm(String s) {
    String cleaned = s.replaceAll("\\s", "");
    char[] chars = cleaned.toLowerCase().toCharArray();
    Arrays.sort(chars);
    return new String(chars);
}


Most important searching for anagrams can use a map from canonical value to string(s).
For ease of mapping to the original algorithm. the mapped-to value is a concatenation of anagrams:

public static String searchAnagram(String[] strings) {
    Map&lt;String, String&gt; canonicalToValue = new HashMap&lt;&gt;();
    for (String s : strings) {
        s = s.replace('\t', ' '); // Omit tabs, reserve them for our usage.
        String canonical = canonicalForm(s);
        canonicalToValue.merge(canonical, s, (oldS, s) -&gt; oldS + "\t" + s);
    }
    return canonicalToValue.values().stream()
            .filter(s -&gt; s.contains('\t'))                
            .collect(Collectors.joining(", "));
}


I use a tab (\t) as it seems that spaces might occur in strings.
One could also use a slash (" / ").

Better yet would be to return a List&lt;String&gt; of anagrams, and keep a List&lt;String&gt; or Set&lt;String&gt; as map value. A TreeSet&lt;String&gt; would remove duplicates and is sorted.

Instead of isAnagram one only needs canonicalForm (better anagramForm?).

The complexity is reduced in code complexity, faster.
Your attempt to optimize sorting on length is just a partial optimizing, needing extra checks / not fitting entirely. By using a HashMap on the canonical form of a string,
one has exactly an immediate search result.

The solution could give "malmodera malordema marmelado melodrama, gasometro gasometro somertago".

No result as String would better be an empty String. Again a List seems more usable.