Java 中 char 和 String 的区别 在java中char和string的区别是什么?如何使用?

java\u4e2dchar\u4e0eString\u7684\u533a\u522b\uff1f

1\u3001\u7c7b\u578b\u4e0d\u540c
char\u662f\u5b57\u7b26\u7c7b\u578b\uff0c String\u662f\u5b57\u7b26\u4e32\u7c7b\u578b\u3002
2\u3001\u5305\u542b
String\u5b57\u7b26\u4e32\u662f\u7528\u6765\u5305\u542b\u4e32\u7684\uff0c char\u662f\u7528\u6765\u5305\u542b\u5355\u5b57\u7b26\u7684\u3002
\u4f8b\u5982\uff1a
char a='1';//\u5b9a\u4e49\u4e00\u4e2a\u5b57\u7b26
String b="dadsa";//\u5b9a\u4e49\u4e00\u4e2a\u5b57\u7b26\u4e323\u3001\u5b58\u50a8
String\u5185\u90e8\u7528\u6765\u5b58\u50a8\u7684\u7ed3\u679c\u662f\u4e00\u4e2achar\u5b57\u7b26\u6570\u7ec4\u3002private final char value[];//\u8fd9\u662fstring\u4e2d\u7528\u6765\u5b58\u50a8\u503c\u7684\u7ed3\u6784\u3002
4\u3001\u5b9a\u4e49
char \u5b9a\u4e49\u65f6\u7528\u5355\u5f15\u53f7 \uff0c\u53ea\u80fd\u6709\u4e00\u4e2a\u5b57\u6bcd\u6570\u5b57\u3002
String\u5b9a\u4e49\u65f6\u7528\u53cc\u5f15\u53f7 \uff0c\u53ef\u4ee5\u662f\u4e00\u4e2a\uff0c\u6216\u8005\u591a\u4e2a\u5b57\u6bcd\u6216\u6c49\u5b57\u7b49\uff0c\u5c31\u662f\u6240\u8c13\u7684\u5b57\u7b26\u4e32\u3002

\u6269\u5c55\u8d44\u6599\uff1a\u4f7f\u7528\u65b9\u6cd5
1\u3001char
#include
using namespace std;
int main()
{
char* pstr = "hello world";
pstr = "aa";
pstr[1] = "a";//\u62a5\u9519
cout<<pstr<<endl;
}
2\u3001string\u7684\u5b9a\u4e49\u5b57\u7b26\u4e32
#include
#include
using namespace std;
int main()
{
string str1;
str1= "hello world";
str1="aa";
str1[1]="a";
cout<<str1<<endl;
}

char\u5b9a\u4e49\u65f6\u7528\u5355\u5f15\u53f7\uff0c\u53ea\u80fd\u6709\u4e00\u4e2a\u5b57\u6bcd\uff0c\u6570\u5b57\u3002char
c='c';
\u800cString\u7528\u53cc\u5f15\u53f7\uff0c\u53ef\u4ee5\u662f\u4e00\u4e2a\uff0c\u4e5f\u53ef\u80fd\u662f\u591a\u4e2a\u5b57\u6bcd\uff0c\u6c49\u5b57\u7b49\u3002\u5c31\u662f\u6240\u8c13\u7684\u5b57\u7b26\u4e32\u3002String
s="adsaf";
char\u53ea\u662f\u4e00\u4e2a\u57fa\u672c\u7c7b\u578b\uff0c\u800cString
\u662f\u4e00\u4e2a\u7c7b\uff0c\u53ef\u4ee5\u76f4\u63a5\u5f15\u7528\u3002
\u6bd4\u5982char
c='c';\u4e0d\u80fd\u76f4\u63a5\u5bf9c\u8c03\u7528\u65b9\u6cd5\u3002
String
s="abc";
\u8fd9\u65f6\u53ef\u4ee5\u8c03\u7528s.charAt(0);\u7b49\u65b9\u6cd5,\u56e0\u4e3aString\u662f\u7c7b\uff0c\u8fd9\u662f\u5c31\u662f\u5bf9\u8c61\u7684\u8c03\u7528\u4e86

1.   类型不同,char是字符类型, String是字符串类型

2、String字符串是用""来包含串的, char是用''来包含单字符的


3、String内部用来存储的结果是一个char字符数组。




1.   类型不同,char是字符类型, String是字符串类型

2、String字符串是用""来包含串的, char是用''来包含单字符的

char a='1';//定义一个字符
String b="dadsa";//定义一个字符串

3、String内部用来存储的结果是一个char字符数组。

private final char value[];//这是string中用来存储值的结构。


5,java中的char和String



扩展阅读:java windowbuilder ... java python ... javascript 在线 ... string ... javascript入门 ... java中字符char转数字 ... java入门网站 ... java ... java中else if ...

本站交流只代表网友个人观点,与本站立场无关
欢迎反馈与建议,请联系电邮
2024© 车视网