java String 类的基本方法
2016-01-17 19:15
453 查看
1.String.subString(int i )字符串截取,从第i个字符串截取直到字符串的末尾。
2.String.subString(int beginindex,int endindex)从beginindex开始截取到endindex。
运行结果:
his is my food
hi
3.String.charAt(i) 返回指定索引值出的char值。索引的范围是从0 到length-1。
运行结果:h。
2.String.subString(int beginindex,int endindex)从beginindex开始截取到endindex。
public class SubString { public static void main(String[] args) { String a =" this is my food"; /*System.out.println("index of letter 's' ="+a.indexOf('s')); System.out.println("index of letter 'o'="+a.indexOf('a'));*/ System.out.println(a.substring(2)); System.out.println(a.substring(2, 4)); } }
运行结果:
his is my food
hi
3.String.charAt(i) 返回指定索引值出的char值。索引的范围是从0 到length-1。
public class SubString { public static void main(String[] args) { String a =" this is my food"; System.out.println(a.charAt(2)); } }
运行结果:h。
相关文章推荐
- javaweb多工程相互引用
- Caught exception while loading file struts-default.xml - [unknown ]
- javac 不是内部或外部命令
- 5 Maven-依赖详解
- 关于获取Java的调用栈的实现
- eclipse 插件安装问题
- java(14)--servlet生命周期
- spring MVC和struts2区别
- Eclipse设置背景与字体大小
- MacBook开发程序的配置问题
- 4 Maven-坐标
- javaEE之--------Spring简介
- Eclipse修改编码后乱码解决
- 使用springMVC上传文件
- 4、函数
- 解决jetty运行时,出现A full JDK (not just JRE) is required问题
- 从头认识java-18.2 基本的线程机制(3)-线程的返回与sleep
- 更新Android SDK之后Eclipse…
- java.lang.ClassNotFoundException…
- 面向对象概述、类与对象、封装、构造函数、this关键字