Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Why String and StringBuffer works differently, discrimination?

0
Posted

Why String and StringBuffer works differently, discrimination?

0

// Test.java public class Test { public static void main(String[] args) { String s1 = new String(“hello”); String s2 = new String(“hello”); StringBuffer sb1 = new StringBuffer(“hello”); StringBuffer sb2 = new StringBuffer(“hello”); System.out.println(“String: s1.equals(s2) = ” + s1.equals(s2)); System.out.println(“StringBuffer: sb1.equals(sb2) = ” + sb1.equals(sb2)); } } // output /* String: s1.equals(s2) = true StringBuffer: sb1.equals(sb2) = false */

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123