Java学习-----02.数组和字符串

数组:
  数组的定义;
    声明数组、分配空间、赋值
  数组对象的创建;
  元素为引用数据类型的数组;
  二维数组;
  二维数组初始化;
  复制数组: arraycopy()方法

字符串:
  java.long.String 类,不可变字符序列
  类常用方法:
    public char charAt(int index)
    返回字符串中第index个字符。
    public int length()
    返回字符串的长度。
    public int indexOf(String str)
    返回字符串中出现str的第一个位置
    public int indexOf(String str,int fromIndex)
    返回字符串中从fromIndex开始出现str的第一个位置
    public boolean equalsIgnoreCase(String another)
    比较字符串与another是否一样(忽略大小写)
    public String replace(char oldChar,char newChar)
    在字符串中用newChar字符替换oldChar字符
    public boolean startsWith(String prefix)
    判断字符串是否以prefix字符串开头
    public boolean endsWith(String suffix)
    判断字符串是否以suffix字符串结尾
    public String toUpperCase()
    返回一个字符串为该字符串的大写形式
    public String toLowerCase()
    返回一个字符串为该字符串的小写形式
    public String substring(int beginIndex)
    返回该字符串从beginIndex开始到结尾的子字符串
    public String substring(int beginIndex,int endIndex)
    返回该字符串从beginIndex开始到endIndex结尾的子字符串
    public String trim()
    返回将该字符串去掉开头和结尾空格后的字符串
  字符串长度;
  字符串比较:euqals()方法
  字符串拼接:①+号 ②concat()方法
  字符串提取:
    public int indexOf(int ch) ;public int indexOf(String value)
    搜索第一个出现的字符ch(或字符串value)
    public int lastIndexOf(int ch) ;public int lastIndexOf(String value)
    搜索最后一个出现的字符ch(或字符串value)
    public String substring(int index)
    提取从位置索引开始的字符串部分
    public String substring(int beginindex, int endindex)
    提取beginindex和endindex之间的字符串部分
    public String trim()
    返回一个前后不含任何空格的调用字符串的副本

  StringBuffer和StringBuilder
  可变的字符序列
  区别:StringBuffer线程安全,StringBuiler非线程安全;
  常用方法:
    public StringBuffer append(…)
    可以为该对象添加字符序列,返回添加后的该对象引用
    public StringBuffer insert(…)
    为该StringBuffer对象在指定位置插入字符序列,返回修改后的该StringBuffer对象引用
    public StringBuffer reverse()
    用于将字符序列逆序,返回修改后的该StringBuffer对象引用。

基本数据类型包装类:
  这些类封装了一个相应的基本数据类型数值,并为其提供了一系列操作。

Math类:
  提供了一系列静态方法用于科学计算;其方法的参数和返回值类型一般为double型。
    abs 绝对值
    acos,asin,atan,cos,sin,tan
    sqrt 平方根
    pow(double a, double b) a的b次幂
    log 自然对数
    exp e为底指数
    max(double a, double b)
    min(double a, double b)
    random() 返回 0.0 到 1.0 的随机数
    long round(double a) double型的数据a转换为long型(四舍五入)
    toDegrees(double angrad) 弧度->角度
    toRadians(double angdeg) 角度->弧度

猜你喜欢

转载自www.cnblogs.com/sealwarm/p/9494866.html