欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

String All Methods

发布时间:2024/10/12 编程问答 52 豆豆
生活随笔 收集整理的这篇文章主要介绍了 String All Methods 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

1、public char charAt(int index)

1 public class Test{ 2 public static void main(String args[]){ 3 String s="hello world!";//返回这个字符串的指定索引处的char值 4 char c0=s.charAt(0);//第一个char值的索引为0. 5 //char c1=s.charAt(20); 6 //IndexOutOfBoundsException抛出异常,index参数为负或不小于该字符串的长度. 7 System.out.println(c0); 8 } 9 }

 

2、public int codePointAt(int index)

1 public class Test{ 2 public static void main(String args[]){ 3 String s="hello world!";//返回指定索引处的字符(Unicode代码点) 4 int i=s.codePointAt(0);//其范围从0到length()-1 5 System.out.println(i); 6 } 7 }

 

转载于:https://www.cnblogs.com/MazeHong/p/5803482.html

总结

以上是生活随笔为你收集整理的String All Methods的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。