数组、字符串和枚举

数组

  • 一维数组实例化:int[ ] d = new int[4];

  • 二维数组实例化:int[ ] [ ] d = new int[4] [4];

  • 当数组下标出错(小于0或大于数组元素个数),Java 产生 ArrayIndexOutOfBoundsException异常。

  • 数组一旦创建后,不能调整大小,但可使用相同的引用变量来引用一个全新的数组。 例:int []a = new int[6]; a = new int[10];

字符串

获取字符串长度

public String length()

字符串比较

//给定字符串的内容是否与s相等,区分大小写 public boolean equals(String s)

//给定字符串的内容是否与s相等,不区分大小写 public boolean equalsIgnoreCase(String s)

//给定字符串是否以prefix开始 public boolean startsWith(String prefix)

//给定字符串的从toffset 处开始的子串是否以prefix开始 public boolean startsWith(String prefix, int toffset)

字符串截取子串

//返回从beginIndex开始到结尾的子串 public String substring(int beginIndex)

//返回从beginIndex至endIndex为止(不包括)的子串 public String substring(int beginIndex, int endIndex)

字符串查找

字符串修改

//将原有字符串中所有的oldChar字符全部替换成newChar public String replace(char oldChar, char newChar)

public String toLowerCase()//转成小写 public String toUpperCase()//转成大写

public String trim()//去掉前后的空格

枚举

[protected | private | abstract] enum 枚举类型标识符(名称){ 枚举常量1, 枚举常量2, …, 枚举常量n } 例如: public enum Color { RED, GREEN, BLANK, YELLOW }

  • 不能通过new运算符创建实例对象,可直接通过枚举类型标识符访问枚举变量,如: Season s1= Season.春季;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值