+ 1

What is the difference between string and char?

char and string are two datatypes..but we used both alphabets carrier! tell me the full description!

2nd Nov 2016, 10:02 AM
ankit
ankit - avatar
9 Answers
+ 3
char is just one character eg: "h"
2nd Nov 2016, 10:25 AM
Ziyaan Hassan
Ziyaan Hassan - avatar
+ 3
Ziyaan, you wrote: >> char is just one character eg: "h" << which is half true. Char is one character, it is true, but you have to write it like this: 'h'. When you write it like this: "h" it means String with just one character in it. Strings are objects, and char is primitive type. You can type System.out.print("h".length()) /try this in Code Playground/ and as a result you'll get the length of object "h".
2nd Nov 2016, 12:11 PM
Mike Levis
Mike Levis - avatar
+ 2
char is only one single character & stores memory a little bit lower than string. eg: char "a" string "apple" they both need " " or ' ' (double quote). cmiiw😅
2nd Nov 2016, 6:15 PM
Nadhifa Sofia
Nadhifa Sofia - avatar
+ 1
char is single character written in single quote but in case of string it is group of character it is written in double quote
2nd Nov 2016, 4:25 PM
ANAND ALABAL
ANAND ALABAL - avatar
+ 1
char datatype is included in between single quotes ' ' whereas to declare a string u need to put it in double qoutes "abhinav"
3rd Nov 2016, 6:11 PM
Anoop Sharma
Anoop Sharma - avatar
0
thank you ziyaan
2nd Nov 2016, 10:28 AM
ankit
ankit - avatar
0
char means just 1 character like'g'....n string means group of character in "-" this like "char"
3rd Nov 2016, 5:39 AM
Ganesh Boyane
Ganesh Boyane - avatar
0
in string we maintaining the sequence of characters
3rd Nov 2016, 5:41 AM
Ganesh Boyane
Ganesh Boyane - avatar
0
char contains only single inverted commas but in string we have to put double qoutes ! @nadhifa_sofia 😉
5th Nov 2016, 5:55 AM
ankit
ankit - avatar