Java的String类型

1. Java基础类型

基础类型封装类
byteByte
shortShort
intInteger
longLong
floatFloat
doubelDouble
charCharacter

2. String

显而易见String并不是Java的8大基础类型,String是一个类,String还有一个名字叫引用数据类型。

int a=10;
String s; 
String s1="Hello";

a在栈中就拥有10的值,但是s只是一个String的管理者类似于C中的指针
例如

String s; 

只是有了一个叫s的老大 管理员,但是现在s的手下还没有小弟。(而且我们的s不是很厉害,一次只能带一个小弟
现在呢?

String s1="Hello";

s1管理员手下有了一个叫Hello的小弟,
俗话说一字符串不容二String好吧这是窝自己杜撰的。

s=s1;

是不是我们的s也带了一个叫Hello的小弟呢?并不是喔,同样拿指针来理解ss1管理的Hello是同一个人(有时候一个Boss就很蓝瘦了,现在居然来2个?Hello哥表示非常悲伤开心)
Sring无法使用foreach循环

String的methods总结

在这不得不强调一遍,Java中并没有办法对一个String本身做事情,所有的String resulting都是一个替身使者这点窝们可以看看总结表下面的2个substring Methods都会return一个String回来就很好理解这个事情了
以下method全部摘自Java SE

ReturnMethodDescription
charcharAT(int index)Returns the char value at the specified value
boolenequals(Object anObject)Compares this string to the specified object .
intlength()Returns the length of this string.
intindexOf(int ch)Returns the index within this string of the first occurrence of the specified character.
intindexOf(int ch,int fromIndex)Returns the index within this string of the first occurrence of the specified character, starting the search at the specified index.
intindexOf(String str)Returns the index within this string of the first occurrence of the specified substring.
intlastIndexOf(int ch)Returns the index within this string of the last occurrence of the specified character.
intlastIndexOf(int ch,int fromIndex)Returns the index within this string of the last occurrence of the specified character, searching backward starting at the specified index.
intlastIndexOf(String str)Returns the index within this string of the last occurrence of the specified substring.
intlastIndexOf(String str,int fromIndex)Returns the index within this string of the last occurrence of the specified substring, searching backward starting at the specified index.
stringsubstring(int beginIndex)Returns a string that is a substring of this string.返回beginIndex后面的substring
stringsubstring(int beginIndex,int endIndex)Returns a string that is a substring of this string.返回beginIndex到endIndex前面一个位置的那个substring
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值