首页 > 编程知识 正文

mayo源码分析,libevent源码分析

时间:2023-05-04 03:51:28 阅读:285910 作者:4134

charAt是String的内置方法 

charAt方法的源码:

public char charAt(int index) { if ((index < 0) || (index >= value.length)) { throw new StringIndexOutOfBoundsException(index); } return value[index]; }

这个方法就是 取出字符串指定位置的字符。index就是索引值。

index的范围就是0 ~ index.length-1,如果超出这个范围就会抛出越界异常StringIndexOutOfBoundsException。

public class Test { public static void main(String[] args) { String s = "With great power comes great responsibility. This is my gift, my curse."; System.out.println("取出第二个字符:"+s.charAt(1)); }}

运行结果:

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。