Remove all adjacent duplicates For this problem, I came up with this ugly solution of appending the characters to the output and in case there is adjacent duplicate deleting from the output. Considering StringBuilder.deleteCharAt(i) is O(N), performance is O(N) + O(N) = O(N).

Please critique this, if this is a right way.

public static String removeDuplicate(String s) {
StringBuilder builder = new StringBuilder();
char lastchar = '\0';
for (int i = 0; i &lt; s.length(); i++) {
  String str = builder.toString();
  if (!str.equals("")
      &amp;&amp; (str.charAt(str.length() - 1) == s.charAt(i))) {
    builder.deleteCharAt(str.length() - 1);
  } else if (s.charAt(i) != lastchar)
    builder.append(s.charAt(i));
  lastchar = s.charAt(i);
}
return builder.toString();
}


Sample input outputs: 


  Input:  azxxzy 
  Output: ay
  
  Input: caaabbbaacdddd 
  Output: Empty String
  
  Input: acaaabbbacdddd 
  Output: acac
General
Your code formatting is all over the place. You should use consistent and structured indentation. See the Java Code-Style guide for, well, guidance.
if I take your code, and re-format it (Eclipse, CtrlA and CtrlshiftF), it looks like:

public static String removeDuplicate(String s) {
    StringBuilder builder = new StringBuilder();
    char lastchar = '\0';
    for (int i = 0; i &lt; s.length(); i++) {
        String str = builder.toString();
        if (!str.equals(&quot;&quot;) &amp;&amp; (str.charAt(str.length() - 1) == s.charAt(i))) {
            builder.deleteCharAt(str.length() - 1);
        } else if (s.charAt(i) != lastchar)
            builder.append(s.charAt(i));
        lastchar = s.charAt(i);
    }
    return builder.toString();
}


At least this allows us to see what you are doing.
Algorithm
A nice algorithm will take data from the input string, and add it to the output if it should be added. A system where you do multiple conversions, add things, and remove things, is complicated, and hard to follow.
Additionally, the null character \0 is actually a valid character in Java, so you may have (an extremely rare) bug.
I do not like that your code is removing all the duplicate values, it seems more practical to remove all but one of the duplicates, but you do not explain why it is supposed to be this way.
More Information required
The above, in itself, is a review, but, if you update your question with the requested details:

recursion yes/no/why?
dedup all, or all-but-one?

then I can add suggestions as to how to solve this in a more efficient way.