@ -18,7 +18,7 @@ true
|
||||
You can create a String Object in the following ways:
|
||||
|
||||
1. `String str = "I am a String"; //as a String literal`
|
||||
1. `String str = "I am a " + "String"; //as a constant expression`
|
||||
1. `String str = "I" + " am" + " a" + " String"; //as a constant expression (note that spaces are in the quotes)`
|
||||
1. `String str = new String("I am a String"); //as a String Object using the constructor`
|
||||
|
||||
You might be thinking: What's the difference between the three?
|
||||
@ -82,9 +82,11 @@ s3: example
|
||||
```
|
||||
|
||||
#### Comparing Strings
|
||||
|
||||
If you want to compare the value of two String variables, you can't use `==`. This is due to the fact that this will compare the references of the variables
|
||||
and not the values that are linked to them. To compare the stored values of the Strings you use the `.equals()` method.
|
||||
|
||||
|
||||
```java
|
||||
boolean equals(Object obj)
|
||||
```
|
||||
|
Reference in New Issue
Block a user