Home >Java >javaTutorial >Difference between Strings and Character Literals

Difference between Strings and Character Literals

王林
王林Original
2024-07-18 21:33:311099browse

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!

Statement:
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