== is used to check whether the references are of the same object..equals () is used to check whether the contents of the objects are the same.But with respect to strings, object refernce with same contentwill refer to the same object.String str1=”Hello”;String str2=”Hello”;(str1==str2) and str1.equals(str2) both will be true.If you take the same example with Stringbuffer, the results would be different.Stringbuffer str1=”Hello”;Stringbuffer str2=”Hello”;str1.equals(str2) will be true.str1==str2 will be false.
Java
Topic: Object
What is the importance of == and equals () method with respect to String object?
Browse random answers:
What is the value of "d" after this line of code has been executed?double d = Math.round ( 2.5 + Math.random( )); What is the value of "d" after this line of code has been executed?double d = Math.round ( 2.5 + Math.random( ));A. 2B. 3C. 4D. 2.5
Which of the following would compile without error?A. int a = Math.abs(-5);B. int b = Math.abs(5.0);C. int c = Math.abs(5.5F);D. int d = Math.abs(5L);
Which of the following are valid calls to Math.max? Math.max(1,4) Math.max(2.3, 5) Math.max(1, 3, 5, 7) Math.max(-1.5, -2.8f)A. 1, 2 and 4B. 2, 3 and 4C. 1, 2 and 3D. 2, 3 and 4
public class Myfile { public static void main (String[] args) { String biz = args[1]; String baz = args[2]; String rip = args[3]; System.out.println("Arg is " + rip); } }Select how you would start the program to cause it to print: Arg is 2A. java Myfile 222B. java Myfile 1 2 2 3 4C. java Myfile 1 3 2 2D. java Myfile 0 1 2 3
What will be the output of the program?String x = new String("xyz");String y = "abc";x = x + y;How many String objects have been created?A. 2B. 3C. 4D. 5
What will be the output of the program?public class Example { public static void main(String [] args) { double values[] = {-2.3, -1.0, 0.25, 4}; int cnt = 0; for (int x=0; x < values.length; x++) { if (Math.round(values[x] + .5) == Math.ceil(values[x])) { ++cnt; } } System.out.println("same results " + cnt + " time(s)"); }}A. same results 0 time(s)B. same results 2 time(s)C. same results 4 time(s)D. Compilation fails.
What is the base class of all classes?
What do you think is the logic behind having a single base class for all classes?
Why most of the Thread functionality is specified in Object Class?
What is the importance of == and equals () method with respect to String object?
Is String a Wrapper Class or not?
How will you find length of a String object?
How many objects are in the memory after the exection of following code segment?
What is the difference between an object and object reference?
What will trim () method of String class do?
What is the use of java.lang.Class class?
What is the possible runtime exception thrown by substring () method?
What is the difference between String and String Buffer?
What is the use of Math class?
Can you instantiate Math class?
What will Math. abs () do?
What will Math. ceil () do?
What will Math. floor () do?
What will Math. ax () do?
What will Math. in() do?
What will Math. Random () do?