---
title: "Comment by Zafeer Rangoonwala on \"Why should we prefer using .equals() to == while comparing strings in Java?\" | Hashnode"
description: "When working with string builder .equals() method apparently doesn&#39;t work. In order to make it work you first need to convert the string builder to string b"
url: "https://hashnode.com/posts/why-should-we-prefer-using-equals-to-while-comparing-strings-in-java/61f022a587fd2728e7cd38e9/comment/61f03ad487fd2728e7cd3c67"
---

[Discussion](https://hashnode.com/posts/why-should-we-prefer-using-equals-to-while-comparing-strings-in-java/61f022a587fd2728e7cd38e9)

Comment [Why should we prefer using .equals() to == while comparing strings in Java?](https://hashnode.com/posts/why-should-we-prefer-using-equals-to-while-comparing-strings-in-java/61f022a587fd2728e7cd38e9)

[Zafeer Rangoonwala](https://hashnode.com/@Zafeer-R)

[Jan 25, 2022](https://hashnode.com/posts/why-should-we-prefer-using-equals-to-while-comparing-strings-in-java/61f022a587fd2728e7cd38e9/comment/61f03ad487fd2728e7cd3c67)

When working with string builder .equals() method apparently doesn't work. In order to make it work you first need to convert the string builder to string by using `.toString()` and then use `.equals()`.

Eg:

`sb1.toString().equals(sb2.toString());`

Everything else is just perfect and I felt like adding this piece of information. 😊

[Samadrita Shaw](https://hashnode.com/@shawsamadrita)

[Jan 25, 2022](https://hashnode.com/posts/why-should-we-prefer-using-equals-to-while-comparing-strings-in-java/61f022a587fd2728e7cd38e9/comment/61f03ad487fd2728e7cd3c67#reply-61f03d7387fd2728e7cd3cf3)

Yes, you're right. Actually this blog post only includes about how == differs from .equals() and that's why I haven't included anything about Stringbuilder as that is a bit different concept.

Thank you for adding this information, this might help someone! 😄
