From the course: Java 8 Essential Training
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Comparing string values - Java Tutorial
From the course: Java 8 Essential Training
Comparing string values
- There are many scenarios where you need to compare strings to each other. And using simple equality operators as you might do with numbers, doesn't work the way you'd expect. In this project, CompareStrings, I've declared two string variables. They both have the same value, a string of Hello. I'm going to add a bit of conditional code. In Java you can write some simple conditional code with the if statement. The if statement places a boolean condition inside a pair of parentheses. And I'll compare str1 to str2 using the == operator. That's called the equality operator and it works great with primitive numbers, booleans, and characters. With strings it might appear that it works also. If this condition is true, I'll output a string to the console of They match! Then I'll add an else clause after the if clause and in that section I'll output They don't match! Then I'll run the code. Everything seems to match expectations. The two strings are identical and I get back They match! But…
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
-
-
-
-
-
-
-
(Locked)
Working with object data types6m 27s
-
Using the String class5m 5s
-
(Locked)
Converting primitive values to strings4m 15s
-
(Locked)
Building a string from multiple values8m 44s
-
(Locked)
Comparing string values5m 51s
-
(Locked)
Formatting numeric values as strings4m 41s
-
(Locked)
Parsing string values3m 13s
-
(Locked)
Working with dates and times8m 35s
-
(Locked)
Challenge: Creating a simple calculator application1m 28s
-
(Locked)
Solution: Creating a simple calculator application1m 19s
-
(Locked)
-
-
-
-
-
-
-
-