Java - Write code to Compares to StringBuilders by their content

Requirements

Write code to Compares to StringBuilders by their content

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        StringBuilder a = new StringBuilder();
        StringBuilder b = new StringBuilder();
        System.out.println(haveEqualContent(a, b));
    }//from ww w . jav a2  s  .c  o  m

    /**
     * Compares to StringBuilders by their content (and nothing else).
     * This is helpful, since two StringBuilder's may have the same
     * content, but the method equals returns false. It seems, some
     * other attributes of StringBuilder are considered as well, unfortuantely.
     */
    public static boolean haveEqualContent(StringBuilder a, StringBuilder b) {
        boolean returnValue = false;

        if ((a != null) && (b != null)) {
            returnValue = a.toString().equals(b.toString());
        } // no else

        if ((a == null) && (b == null)) {
            returnValue = true;
        } // no else

        return returnValue;
    }
}

Related Exercise