Home Tutorialhelp Comment Clarification on equals method of StringBuffer

 
 

Comment

Sivakumar Ganti
Clarification on equals method of StringBuffer,
July 14, 2010 at 4:55 PM

// spring buffer will evaulate to false while comparing two strings.But in the above tutorial it is said as true.

public static void main(String[] args) {


StringBuffer sb = new StringBuffer("hello1");
StringBuffer sb1 = new StringBuffer("hello1");



// this would be false because String buffer does not have
// an equals method and the control would pass on to StringBuffer
// equal method.
// The Objects equal method will not know it wwere just two
// string , they are just two objects.
if(sb.equals(sb1)){
System.out.println("String buffer equals");
}else
System.out.println("String buffer not equals");



// == equal compares the memory location and hence since
// they are two different objects it will be false.
if(sb == sb1){
System.out.println("String buffer == equals");
}else
System.out.println("String buffer not== equals");


}
View All Comments | View Tutorial
Advertisement
Related Tutorial and Articles
Java Beginners

StringBuffer and StringBuilder
and sbu2 will get different refence ids; here equals method of Object class...StringBuffer and StringBuilder  package org.day.strings; import...[] args) { StringBuffer sb1 = new StringBuffer(); sb1.append 

Java Beginners

StringBuilder v/s StringBuffer - Java Beginners
between StringBuilder & StringBuffer classes. I know that StringBuffer... inefficient. StringBuilder (or StringBuffer) are better choices in these cases... of programming can be used. StringBuilder is basically identical to the older StringBuffer 

Java Tips and Examples

StringBuffer and StringBuilder
Java NotesStringBuffer and StringBuilder StringBuffer is used to store.... StringBuilder was added in Java 5. It is identical in all respects to StringBuffer except... in the java.lang package. StringBuffer and StringBuilder methods and constuctors 

Java-Tutorials

Differences between the String, StringBuilder, and StringBuffer classes
Differences between the String, StringBuilder, and StringBuffer classes StringBuffer versus String Java provides the StringBuffer and String classes... for the concatenation creates a StringBuffer object, then invokes its append method 

Java Beginners

StringBuilder v/s StringBuffer - Java Beginners
StringBuilder v/s StringBuffer  Hi, Thank you for your prompt... Threads run simultaneously. But in case of BOTH StringBuilder & StringBuffer...(); System.out.println(str); StringBuffer read = new StringBuffer("I JAVA." 

Java Beginners

StringBuffer - Java Beginners
StringBuffer  Hi, Thank you so much for answering my previous question regarding StringBuilder And StringBuffer. But,while using more than one...-threaded applications(i.e. StringBuffer)? Please give example(code) and explain 

Java Beginners

String and StringBuffer - Java Beginners
; Hi vijay Java provides the StringBuffer and String classes.... Simply stated, objects of type String are read only and immutable. The StringBuffer... performance difference between these two classes is that StringBuffer is faster 

Java Interview Questions

equals and hashcode
to the equals() method because it is inherited from the Object class. However, this default... can override the default implementation of the equals() method defined...equals and hashcode  Could you please explain me why equals 

Programming Tutorials

equals method in java
Description: The equals method found in java.lang.object. It is use to check  state(data) of object not identifying the location in Memory of the object. It return the Boolean value. In other way it compare content of  

Java Beginners

Equals() and Hashcode() - Java Beginners
Equals and HashCode() are the methods of Object class. The Equals() method returns...Equals() and Hashcode()  What is Equals() and Hashcode()? what... these methods while using Hashtable? Please Explain it detaily along with an java 

Java Tips and Examples

Summary - java.util.StringBuilder and java.util.StringBuffer
Java: Summary - java.util.StringBuilder and java.util.StringBuffer... can be quite inefficient. StringBuilder (or StringBuffer) are better choices...;new StringBuffer(n) Creates empty StringBuilder with initial capacity n 

Java Tips and Examples

Java - StringBuffer class in Java
Java - StringBuffer class in Java       In this example you will learn about StringBuffer class. This example explains how you can use functions provided by the StringBuffer 

Programming Tutorials

Use of equals() method of  FloatBuffer class in java.
Use of equals() method of  FloatBuffer class in java.  ... equals(object obj) The equals() method tells this buffer is equals... C:\>java FloatEqualDemo Equals Equals Not equals 

Programming Tutorials

Use of equals() method of ByteBuffer class in java.
Use of equals() method of ByteBuffer class in java.  In this tutorial, we...; The allocate(..)method allocate a new byte buffer. boolean equals(object obj) The equals() method tells this buffer is equals or not to another 

Java Beginners

further clarification needed - Java Beginners
further clarification needed  Dear Experts, I refer to the last answer you have written to me. The good news is that there's no error already but the code is still not working for me. As Tsuch, I hope to clarify about 

Programming Tutorials

Use of equals() method of LongBuffer class in java.
Use of equals() method of LongBuffer class in java.  In this tutorial, we...(..)method allocate a new long buffer. boolean equals(object obj) The equals() method tells this buffer is equals or not to another 

Programming Tutorials

Use of equals() method of IntBuffer class in java.
Use of equals() method of IntBuffer class in java.  In this tutorial, we...(..)method allocate a new int buffer. boolean equals(object obj) The equals() method tells this buffer is equals or not to another 

Java Beginners

Equals()
Equals()  What is role of equals() method in camparator interface 

Programming Tutorials

Difference between == and equals method in java
Description: For comparing equality of string ,We Use equals() Method... "equals()" method .  "==" compares the reference value of string object whereas equals() method is present in the java.lang.Object 

Java Technology Tutorials

Java file equals
Java file equals This section illustrates you the use of method equals... file class objects using equals() method. This method checks whether...); } } Through the method equals(), you can check the equality of two file 

Java Tips and Examples

Summary: Graphics
Java: Summary: Graphics This is a summary of simple graphics methods... without underscores for pre-Java 1.4) Color.BLACK, Color.WHITE... and overriding the paintComponent method. The constructor should set the background color 

Java Beginners

stringbuffer - Java Beginners
DeleteString { public static void main(String args[]) { StringBuffer sb = new StringBuffer("Rose India Tech"); //Removes the characters at index 10 to 15 in the StringBuffer. sb.delete(10, 15); System.out.println("After delete 

Java Tips and Examples

Summary - String
Java: Summary - String String Concatenation Following table shows how... and interfaces for String class. StringBuilder and StringBuffer are much more.... If a non-String object is concatenated with a String, its toString() method 

General

Java writer api
,  field summary, constructor summary and method summary. Abstract Writer... package.    Writer method summary Abstract class Writer possess several... Java writer api       

Java Interview Questions

AutoBoxing,==,!=,equals() - Java Interview Questions
AutoBoxing,==,!=,equals()  Hi, I am really confused of ==,!=,equals() operations on Autoboxing the new feature in java 5.0 . Can any one tell me....  Java language have 2 data types . 1.Primitive type. 2. Reference 

Java Beginners

StringBuffer - Java Beginners
StringBuffer  Can any one help with this naughty problem? Replacing a character with two characters in a StringBuffer. Replacing a character...;} converting the StringBuffer using charArray[] also worked well, but not where 

Core Java

String reverse in java
; java API provides StringBuffer and StringBuilder  reverse() method which... StringBuffer and StringBuilder methods. For that we will do it by recursive way as well...String reverse in java In this section we are going to discuss about how 

Java Tips and Examples

Summary: GUI Graphics
Java: Summary: GUI Graphics This is a summary of simple graphics methods... of JPanel and overriding the paintComponent method. class MyDrawing extends JPanel... underscores for pre-Java 1.4 Color.BLACK, Color.WHITE 

Programming Tutorials

ShortBuffer in java, Use of equals() method of ShortBuffer class in java.
Use of equals() method of ShortBuffer class in java.  In this tutorial.... boolean equals(object obj) The equals(...) method tells this buffer.... It provides the following methods: Return type Method 

Java Beginners

Overriding equals and hashCode in Java
Overriding equals and hashCode in Java  Overriding equals and hashCode in Java 

Java Beginners

String and stringbuffer object - Java Beginners
String and stringbuffer object  Hi, What is the basic difference between string and stringbuffer object? Thanks   Hi Friend... be changed while StringBuffer class is used to represent characters that can 

Core Java

Difference between equals() and == ?
equals() method in java. The equals() method which is defined in object class. equals() method behave same as the equality operator but rather then checking.... But one more difference is that equals() is a method and "= =" 

Java Beginners

'String' vs 'StringBuffer' - Java Beginners
'String' vs 'StringBuffer'  What should i use String or StringBuffer?  Hi, First you need to rectify the question. Because StringBuffers... StringBuffer when you are append different data to the same StringBuffer object 

Java Beginners

hashcode() and equals() - Java Beginners
hashcode() and equals()  plesae give an example of hashtable using equals() and hashcode()?  Hi Friend, Try the following code...) {this.id = id;} public int hashCode() { return id;} public boolean equals 

Java Tips and Examples

Summary: Methods
Java: Summary: Methods Parameters Method parameters are separated..., double). main If you have a main method, it must be declared public static void main(String[] args) signature To decide which method to call, Java looks 

Java Interview Questions

hashcode() and equals() - Java Interview Questions
hashcode() and equals()  can you give one hashtable prog using equals() and hashcode()?PLease..thanks in advance 

Java Interview Questions

Equals() and Hashcode() - Java Interview Questions
Equals() and Hashcode()  What is Equals() and Hashcode()? what... these methods while using Hashtable? Please Explain it detaily along with an java... of hashtable using equals() and hashcode 

Java Tips and Examples

Summary
Summary       You have been introduced to the basics of Java language providing a great amount... be eager to discover more about Java in the succeeding chapters. The course 

JSP Servlet Questions

clarification in jsp - JSP-Servlet
clarification in jsp  Hi did jsp supports post method to send values to next jsp? if possible how to use post method in jsp?and what is the default method(get/post) of jsp?  Hi Friend, Yes jsp supports Post 

Java Interview Questions

Interview Tips - Java Interview Questions
Interview Tips  Hi, I am looking for a job in java/j2ee.plz give me interview tips. i mean topics which i should be strong and how to prepare. Looking for a job 3.5yrs experience 

Java Tips and Examples

Summary: Math.random() and java.util.Random
Java Summary: Math.random() and java.util.Random Math.random() method.... A standard way to generate random numbers is to use the Math.random() method..., and casting to convert it to an integer. The advantage of this method over 

Java Tips and Examples

Collections Overview
Java NotesCollections Overview Summary of Collections interfaces Most...() and equals() // The following java.lang interfaces are commonly used... PreferencesFor persistent storage of program options. Properties Pre-Java 2, compare 

Java Beginners

Constructors .equals method
Constructors .equals method  Hi, my two dates never match using .equals method and two different constructors. o/p is like examples.Pdate@192d342Blah dateexamples.Pdate@6b97fd Code: package examples; public class Pdate 

Java Beginners

Constructors .equals method
Constructors .equals method  Hi, my two dates never match using .equals method and two different constructors. o/p is like examples.Pdate@192d342Blah dateexamples.Pdate@6b97fd Code: package examples; public class Pdate 

Java Tips and Examples

==, .equals(), and compareTo()
Java Notes==, .equals(), and compareTo() Equality comparison: One way... the equals() method to compare the values of objects. Comparing Object values with the equals() Method Use the equals() method to compare 

Java Tips and Examples

GUI Tips
Java NotesGUI Tips [Beginning of list of GUI tips -- needs much more] Program structure main can be in any class, but it's often simplest to understand if it's in a separate class. main should do very little work 

General

Java BigDecimal equals example
Java BigDecimal equals example       Method evaluates bigdecimal object values as well as the scales allocated to the values. Method returns true only when both bigdecimal 

Java Tips and Examples

Summary - Data
Java: Summary - Data Vanilla Java Basic types to know: int, double, String... and the wrapper classes is largely automatic as of Java 5.... java.util.StringBuilder (as of Java 5) and java.util.StringBuffer (slower than 

Free Magazine

Tips & Tricks
Tips & Tricks          Here are some basic implementations of java language, which you would...?? You got it right! The program below runs without the main method. Here we have 

Java Tips and Examples

Java Notes: Table of Contents
Summary - String Summary - Character Summary - StringBuilder etc GUI summaries Summary - GUI Components... summaries Summary - Basic Elements Summary - Control 

Core Java Tutorials

Write a method which will remove any given character from a string?
. In this tutorial we have used StringBuilder is a mutable sequence of character. It is used as a replacement of StringBuffer. StringBuilder is not synchronized and uses...Write a method which will remove any given character from a string 

Java Tips and Examples

CMIS 102A Java Summary - v7
Java: CMIS 102A Java Summary - v7   In this section we will learn about following topics: a) Keywords, reserved words b) Operators c) String... these declarations for the following method prototypes. int i, j; double d 

Java Interview Questions

Java string buffer
Java string buffer  what is stringBuffer and StringBuilder 

Free Magazine

Tips & Tricks
Tips & Tricks           Splash Screen in Java 6.0 Splash screens... of the application. AWT/Swing can be used to create splash screens in Java. Prior to Java SE 

Java Tips and Examples

OOP Summary
Java: OOP Summary Objects All objects are allocated... be either, but Java supports only object references... annotation provides compiler checking. Polymorphism: When a method is called 

Java Tips and Examples

Summary - Expressions
Java: Summary - Expressions Parentheses () have three uses...) After a method name to enclose parameters. Eg, x = sum(a, b); Around a type name... characters within the Java language that perform operations on arguments to return 

Java Tips and Examples

Summary - Statements
Java: Summary - Statements Each control statements is one logical statement...; Other Flow Control Statements Method Return return; //no value for void method return expr; //method value to return Simple try 

Java Tips and Examples

Creation of StringBuffer
Creation of StringBuffer      ... we have used the following StringBuffer Constructors. StringBuffer() //Default Constructor with 16 characters set StringBuffer(String s) //String to String 

Hibernate Questions

Case-insensitive equals using Hibernate Criteria.
Case-insensitive equals using Hibernate Criteria.  How to use Case-insensitive equals with Hibernate Criteria?   The Case Insensitive... create Persistent class Employee.java‚??Hibernate uses the Plain Old Java Object 

Java Interview Questions

StringBuffer
StringBuffer  What's the difference between these two formats? String string=args[0]; String reverse = new StringBuffer(string).reverse().toString(); String string=args[0]; StringBuffer rev = string.reverse(); String 

Java Tips and Examples

String Comparison
value (have exactly the same characters in them). Use the .equals() method... Java NotesString Comparison Strings can not be compared with the usual <... [to be supplied] Comparing Strings: ==, .equals(), .compareTo(), ... To compare Strings 

Java Interview Questions

difference b/w == and equals()
address whereas the equals() method is used to compare the values of the object...difference b/w == and equals()  what is the difference between == operator and equals()   Hi Friend, The == operator checks if the two 

Free Magazine

Tips 'n' Tricks
Tips 'n' Tricks           Download files data from many URLs This Java program... arguments separated by space. Java provides URLConnection class that represents 

Java Tips and Examples

Summary - Basic Elements
Java: Summary - Basic Elements In this section we will see how to comment your Java code. We will also see the Identifiers and Keyword of Java API. Properly commenting the Java code is very important. Commenting the programming code 

Java Tips and Examples

Summary: DOS Commands
Java Summary: DOS Commands In this section we will discuss about DOS commands. If you are developing Java program on windows then you should learn these DOS... and executing Java programs from DOS prompt. Before Windows, there was the ugly 

Java Tips and Examples

Summary: Math Class
Java Summary: Math Class In this section we will study about the Match class of Java API. Some basic math functions can be found in the Math class... Constants Here is the detailed summary of Match class. Two common 

Java Tips and Examples

Summary - Basic Elements
Java: Summary - Basic Elements In this section we will learn about commenting in Java. We will learn following things: a) Identifiers in Java. b) Object types in Java. c) Code commenting in Java d) Integer types in Java e) Keywords 

Java Beginners

java method
java method  can we declare a method in java like this static { System.loadLibrary("nativelib"); } i have seen this in a java learning E book. i don't understand the static { } plz help me. what kind of method 

Java Tips and Examples

Summary - Control Flow
Java: Summary - Control Flow Each control statement is one logical... (testExpression); Other Flow Control Statements Method Return return; //no value for void method return expr; //method value 

Java Tips and Examples

Summary: Math and java.util.Random Classes
Java Summary: Math and java.util.Random Classes In this section we will discuss Math and java.util.Random classes. Both these classes can be used... Trigonometric Methods All trigonometric method parameters  are measured 

Java Tips and Examples

Appending String in java
. Methods summary for StringBuilder append() method which take any data type... appending string in java. Java provide a method called append.... StringBuilder are in replacement for StringBuffer where synchronization is applied  

Free Magazine

Tips and Tricks
Tips and Tricks        ... in Java Java provides a lot of fun while programming. This article shows you how... and keyboard related operation through java code for the purposes of test automation, self 

Core Java

Concatenate Two Strings in java
Concatenate Two Strings in java We are going to describe how to concatenate of two string. we have use for concat() method, this method joints of two string...) method it means add the two String first-to-end. You can  use anther  

Java Tips and Examples

Summary - Scanner
Java: Summary - Scanner The main use of java.util.Scanner is to read values from System.in or a file. Many Scanner methods fit a simple pattern: nextXYZ... of type XYZ is available to be read next. Additional types. The summary below 

Java Tips and Examples

Summary - EZPanel
Java: Summary - EZPanel Constructors and Methods Assume: int n, String s, boolean b, Component comp Note: All methods return this to permit call chaining. Constructor new EZPanel(); Default constructor. Empty, 12 pixel border 

Java Tips and Examples

Summary - Character
Java: Summary - Character Character class static methods In this section we will see the static methods of Character class. Character class of Java API... characters that are displayed are determined by your browser, not Java 

Free Magazine

Tips and Tricks
Tips and Tricks           Send data from database in PDF file as servlet response... is a java library containing classes to generate documents in PDF, XML, HTML, and RTF 

Java Beginners

java method - Java Beginners
java method  Plz help me on toString() in java  Hi Friend, The Object class provides the method toString() that returns the string..., the toString() method of the object is automatically called. Thanks 

JavaScript Questions

Small clarification
 

Java Beginners

java method - Java Beginners
java method  hi friends, Is there any default return type for methods in java?  There is no default return type in java, as a user you have to specify the return type even void 

Java Tips and Examples

String Buffer insert and append example
:\vinod\Math_package>java AppendInsert StringBuffer insert and append... with StringBuffer and append data to it. The StringBuffer is a class that implements... the insert() method that provides the facility for adding the data in any 

Java Beginners

java method - Java Beginners
java method  i wanna explation about a method for example... Mail[] getAllMails(String userName) I WANNA EXPLATION ABOUT ABOVE METHOD CAN U... and Tutorials on Java Mail visit to : http://www.roseindia.net/javamail/ Thanks 

Java Beginners

pass method reference in java
pass method reference in java  How to pass method reference in Java 

Java Beginners

class method in java
class method in java  How to write a class method in Java?   You must read Java - Class, Object and Methods in Java 

Java Beginners

Using throw in java method
Using throw in java method  using throw with method implies what 

Java Beginners

try catch method in java
try catch method in java  try catch method in java - when and how should i use the try and catch method in Java ?   Please visit the following links: http://www.roseindia.net/help/java/t/java-try.shtml http 

Java Beginners

Java making a method deprecated
Java making a method deprecated  java making a method deprecated In Java how to declare a method depricated? Is it correct to use depricated... or method in Java. Instead of it you can use alternatives that exists. Syntax 

Java Beginners

Static Method in Java
Static Method in Java  Is Overriding Static methods possible in java? If Yes, How 

Java Beginners

getch() method in java
getch() method in java  does someone know how can i obtain the getch() function in java 

Java Beginners

Generic Method - Java Beginners
Generic Method  I want simple java program for Generic Method with explanation 

Java Beginners

Destroy method in java - Java Beginners
Destroy method in java  Hi, What is the implementation of destroy method in java.. is it native or java code? Thanks   Hi Friend, This method is not implemented. Thanks 

Java Tips and Examples

Regular expression summary
Java: Regular expression summary [This text is taken directly from the Java API documentation] Construct Matches   Characters x The character x \\ The backslash character \0n The character 

Java Interview Questions

method inside the method??
method inside the method??  can't we declare a method inside a method in java?? for eg: public class One { public static void main(String[] args) { One obj=new One(); One.add(); private static void add 

Java Beginners

Class and method question, Java?
Class and method question, Java?  Consider a Java class that you... Prompt string** and the following method: getValue displays the prompt and reads..., the method should display an error message and ask the user for a new value 

General

How to Invoke method using Reflection API of Java?
; method of StringBuffer class Now we will learn how to call the "append" method of StringBuffer class using the Java Reflection API. Here is the signature of the append method of the StringBuffer class: public StringBuffer 

Java Interview Questions

Method decleration in java
Method decleration in java  What is the catch or declare rule for method declarations 

Java Beginners

Static method in java - Java Beginners
Static method in java  What are static method in Java  Hi Friend, Please visit the following link: http://www.roseindia.net/java/beginners/howtoaccessstaticmethod.shtml Hope that it will be helpful for you 

Java Interview Questions

getch() method in java
getch() method in java  does someone know how can i obtain the getch() function in java?   Hi Friend, In java, you can use the method next() of Scanner class. Here is an example: import java.util.*; class Hello 

Java Beginners

Java Method Overloading - Java Beginners
Java Method Overloading  can method be overloaded in subclass or not?  Hi Friend, Yes A subclass can overload the methods.For Example...: http://www.roseindia.net/java/master-java/method_overloading.shtml Thanks 

Java Beginners

Java Code - Java Beginners
Java Code  What is the relationship between equals() method & hashCode 

Advertisements Advertisements
 

 

 

DMCA.com