【java基础复习】Numbers和Strings

Numbers

总览

在这里插入图片描述
在这里插入图片描述

Class Character

在这里插入图片描述

Class String

创建Strings

  • String greeting = "Hello world!;
  • char[] helloArray = {'h', 'e', 'l', 'l', 'o', '.' }; String helloString = new String(helloArray);

String类是immutable的。
每当在程序中遇到string literal时,编译器都会自动创建一个包含这个string literal的String对象。

String的长度:
length() instance method.

获取string中某个位置的character:
charAt() instance method.

拼接string:
String concat(String str)

按照一定的delimiter连接和分割string
static String join (CharSequence delimiter, CharSequence... elements)
static String join(CharSequence delimiter, Iterable<? extends CharSequence> elements)
String[] split(String regex)

String valueOf() 函数
完成Numbers或者char[]到String的转换。

String转换为char[]
char[] toCharArray()
void getChars(int srcBegin, int stcEnd, char[] dst, int dstBegin)

String中的替换:
Stirng replace(CharSequence target, CharSequence replacement)

获取某个char的index:
int indexOf(int ch)
int lastIndexOf(int ch)

子字符串:
String subString(int beginIndex, int endIndex)

Class StringBuilder

StringBuilder objects are like String objects, except that they can be modified. Internally, these objects are treated like variable-length arrays that contain a sequence of characters. At any point, the length and content of the sequence can be changed through method invocations.

Length and capacity
在这里插入图片描述
在这里插入图片描述
StringBiulder operations
在这里插入图片描述

You can use any String method on a StringBuilder object by first converting the string builder to a string with the toString() method of the StringBuilder class. Then convert the string back into a string builder using the StringBuilder(String str) constructor.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值