From the course: Java 8+ Essential Training: Syntax and Structure

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Work with character values

Work with character values - Java Tutorial

From the course: Java 8+ Essential Training: Syntax and Structure

Start my 1-month free trial

Work with character values

- [Instructor] Java distinguishes between characters and strings. A character is a primitive data type and it consists of just a single character. A string is a complex object and can reference a complete collection of characters in a particular order. The primitive type is called char c-h-a-r and, just like any of the primitive types, it's spelled in all lowercase. I'll declare a variable of that type that I'll call c1. And I'll give it a literal value of the number one wrapped in single quotes. A literal for the character type is wrapped in single quotes while a literal for the string type is wrapped in double quotes. Now do the same thing for character two. I'll give it a value of two and then I'll create another one with the value of three. So those are three individual primitive values. There's another way of referencing a character and that's by its unicode value. To do this properly, you'll need a unicode chart. And here's one of many that are available on the web. When you're…

Contents