总结4

基本数据类型以及对应包装类

基本数据类型 对应包装类
byte Byte
short Short
int Integer
long Long
char Character
float Float
double Double
boolean Boolean

 

 

 

 

 

 

 

 

 

 

 

装箱和拆箱

   基本类型转为包装类称为装箱,

      例如把 int 包装成 Integer 类的对象;使用包装类的构造方法;valueOf()方法

  包装类转为基本类型称为拆箱,

      例如把 Integer 类的转为 int ; 使用intValue();

 

Math 

  Abs - 求绝对值

  Max/min - 最大值最小值

  random() - 生成一个0-1之间的随机数

 

  Random rand = new Random();

  nt n=rand.nextInt();//生成一个整数类型的随机整数

 

String

  CharAt(int index) ; 返回指定位置的字符

  length() - 求字符串的长度

  Equals() - 比较两个字符串是否相同

  equalsIgnoreCase() - 忽略大小写比较

  toUpperCase() - 转换为大写

  toLowerCase() - 转换为小写

  concat() - 字符串链接, + 是一样的

  public String[] split(String regex):根据给定表达式的匹配拆分此字符串 

方法名

说明

public int indexOf(int ch) 

搜索第一个出现的字符ch(或字符串value),如果没有找到,返回-1

public int indexOf(String value)

public int lastIndexOf(int ch) 

搜索最后一个出现的字符ch(或字符串value),如果没有找到,返回-1

public int lastIndexOf(String value)

public String substring(int index)

提取从位置索引开始的字符串部分

public String substring(int beginindex, int endindex)

提取beginindex和endindex之间的字符串部分

public String trim()

返回一个前后不含任何空格的调用字符串的副本

 

posted @ 2021-12-09 14:48  汪汪汪QVQ  阅读(24)  评论(0)    收藏  举报