Home > Java > javaTutorial > body text

Difference between Strings and Character Literals

王林
Release: 2024-07-18 21:33:31
Original
1071 people have browsed it

Diferença entre Strings e Literais de Caracteres

Is a string consisting of a single character the same as a character literal? For example, is "k" the same as 'k'?

Character Literal:

  • Represents a single letter.
  • Char type.
  • Example: 'k'.

Single Character String:

  • Contains only one letter, but is still a string.
  • String type.

Example: "k".

  • Summary
  • 'k' (character literal) and "k" (single character string) are not the same thing.
  • A character literal is of type char, while a string is of type String.
  • Strings, even when they contain only one character, are different from character literals.

Notice how the n escape sequence is used to generate a new line.
You don't need to use multiple println( ) statements to get multiline output. Just embed n in a longer string at the points where you want the newline to occur.

The above is the detailed content of Difference between Strings and Character Literals. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template