From the course: Java 11+ Essential Training
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Compare string values - Java Tutorial
From the course: Java 11+ Essential Training
Compare string values
- There are many scenarios where you need to compare strings to each other. And using simple equality operators looks like it should work, but it doesn't work the way you might expect. I'm starting in this exercise with two string variables. One declared with explicit typing, the other with an inferred type. They both have the same value of hello and an exclamation mark. I'm going to create an if statement. In Java the if keyword is followed by a pair of parentheses, and the parentheses need to wrap an expression that evaluates as true or false. I'm going to be doing this the wrong way. I'll say if s-one matches s-two, using the double equals operator, the double equals operator works for equality with primitive values, but it's not the right way to do it with objects and I'll show you why. If those two values match, I'll output they match, and I'll add an else clause here, and if I get back false then I'll say…
Contents
-
-
-
-
-
-
(Locked)
Declare and initialize string values3m 55s
-
(Locked)
Build a string from multiple values4m
-
(Locked)
Clone the exercise files from GitHub3m 57s
-
(Locked)
Convert primitive values to strings3m 29s
-
(Locked)
Format numeric values as strings5m 55s
-
(Locked)
Interpolate strings with placeholders3m 7s
-
(Locked)
Compare string values4m 27s
-
(Locked)
Parse string values2m 36s
-
(Locked)
Get string values from user input3m 34s
-
(Locked)
Challenge: A simple calculator1m 9s
-
(Locked)
Solution: A simple calculator1m 18s
-
(Locked)
-
-
-
-
-
-