From the course: Java 8+ Essential Training: Syntax and Structure
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 with methods - Java Tutorial
From the course: Java 8+ Essential Training: Syntax and Structure
Compare String values with methods
- [Instructor] There are many scenarios where you need to compare strings to each other. Using simple equality operators, that is the equals equals operator, as you might do with numbers, doesn't work the way you expect. Here's an example, I've created two string variables named s1 and s2. I'll use a bit of conditional code, I'll type if, then press control shift enter, or command shift return, and that expands to the complete if clause. Now I need to pass in a conditional expression inside the parentheses. I'll use s1 double equals s2. That's the equality operator, and with primitive numbers it's always accurate. Now, if that condition is true, I'll do a little bit of console output. I'll use S out, and I'll output the string "they match". Then I'll move the cursor down here to after the if clause, and type else, once again I'll auto complete my code. And this time, I'll output the string "they don't match". Then I'll run this code. As you would expect, I get the result "they match".…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
Declare and initialize String objects3m 45s
-
(Locked)
Create and concatenate String values4m 34s
-
(Locked)
Convert primitive values to strings5m 30s
-
(Locked)
Build a String from multiple values10m 35s
-
(Locked)
Compare String values with methods5m 19s
-
(Locked)
Format numeric values as strings7m 2s
-
(Locked)
Parse String values4m 10s
-
(Locked)
Challenge: A simple calculator56s
-
(Locked)
Solution: A simple calculator1m 26s
-
-
-