Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
What is the difference between character literals and string literals in Java?
Character literals represents alphabets (both cases), numbers (0 to 9), special characters (@, ?, & etc.) and escape sequences like \n, \b etc.
Whereas, the String literal represents objects of String class.
Example
public class LiteralsExample {
public static void main(String args[]){
char ch = 'H';
String str = "Hello";
System.out.println("Value of character: "+ch);
System.out.println("Value of string: "+str);
}
}
Output
Value of character: H Value of string: Hello
Advertisements
