x.substring(1,2).equals("hello") ;
do we need to say above statement as below
(x.substring(1,2)).equals("hello") ;
please advise
Yes - you can write the original expression
x.substring(1,2).equals("hello")

1)You must use String's equals method to compare the Strings. Don't use == to compare them.
2)You are comparing a substring from "a" with the same thing. You need to compare a substring from "a" to a substring from "b".
3)You are comparing a substring length of 1. But the challenge asks you compare substring length of 2.
4)You don't consider different lengths of input Strings. You could use Math.min method to find the shorter String length.

The output is
>java Test
Yes, aChar + 1 equals bChar
Sure it does
You can see that using == with char really is comparing int values. Look at http://www.scism.lsbu.ac.uk/jfl/Appa/appa4.html
to see values. You see value of 'a' is 97 and value of 'b' is 98.

The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any non-null reference values x and y, this method returns true if and only if x and y refer to the same object (x == y has the value true).

But, the equals method in subclasses(like the String class) override the Object class equals method and compare contents or attributes that make sense for that class.

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Use == for primitives (double, int, char, boolean etc.) <-- these types all start with a lowercase later
Use equals for objects (String, Object, Integer, etc.) <-- these types all start with an uppercase later

In Java, when the “==” operator is used to compare 2 objects, it checks to see if the objects refer to the same place in memory. In other words, it checks to see if the 2 object names are basically references to the same memory location.

>java TestYes, aChar + 1 equals bChar
Sure it does
we got above highlighted output because 97+1=98 right(as 98 is the ordinal number of the character in the range 0 to 255 for 'b Lower case B' as attached from below link)?http://www.scism.lsbu.ac.uk/jfl/Appa/appa4.html

so for char it is ideally better to use == as it is primitive. But practically i can use either == or equals which does same thing functionally right. (== compares ordinal number of the character of aChar and bChar and .equals checks the content hence if(aCharacter.equals(aCharacter))System.out.println("Sure it does"); results Sure it does. Ofcourse downside of using equals with char primitive is i have to cast primitive to object Character type as below before hand right?(so better to use == itself to make coding easy while using char)
Character aCharacter = new Character(aChar);

I see in above example x is character but they are using as string (within " " as "x", not they are not converting char to Character like Character xCharacter=new Character(x)) then using .equals similar to how they use .equals on Objects and String.
Which seems bit odd to me.
Please advise

No. You are comparing a String to a String. Just as Doug pointed out, the substring method returns a String. The String class implements the CharSequence interface. See https://docs.oracle.com/javase/7/docs/api/java/lang/CharSequence.html
So, String is a readable sequence of char values. As Doug posted, some of String's method return char and some return String.

Featured Post

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

There is an easy way, in .NET, to centralize the treatment of all unexpected errors.
First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…

The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…