字符串
来源:互联网 发布:sql cast和convert 编辑:程序博客网 时间:2024/06/06 16:47
字符串的查找
一共两种:indexOf()字符串首位置的查找,lastIndexOf()字符串最后一次出现的位置。返回值为一个整形变量。
String str="we are students";int a=str.indexOf("e");int b=str. lastIndexOf("e");
1.a=3;b=11;(没有查找到值等于-1)
2.在lastIndexOf()中如果查找空字符(lastIndexOf(“”)),最后返回来的值等于这个字符串的长度。
3.获取指定位置的字符str.charAt(5);表示查找str字符串中第五个位置的字符是什么。
4.str.trim()除去空格。只是除去字符串前后的空格,字符串中间的不算!
5.字符的替换(注意大小写)
public class TestString01 {public static void main(String[] args){ String a=" we are student"; String b=a.replace('e','b'); String c=a.trim(); System.out.println(b); System.out.println(c); System.out.println(a.length()); System.out.println(c.trim().length());}}
6.字符串的比较,==的比较不仅比较内容还比较地址!equals()则不考虑。
7.toLowerCase(),toUpperCase(),split();分别表示的是字母大小写的转换和拆分。
0 0
- 字符串
- 字符串
- 字符串
- 字符串
- 字符串
- 字符串
- 字符串
- 字符串
- 字符串
- 字符串
- 字符串
- 字符串
- 字符串
- 字符串
- 字符串
- 字符串
- 字符串
- 字符串
- codeforces #312 B B. Amr and The Large Array(统计)
- java容器类---概述
- Java基础---synchronized 详解
- centos下配置apache用户及用户组权限
- Goldengate(ora11g)配置说明
- 字符串
- cug 1179 暴力之美
- 启动Tomcat提示:指定的服务未安装
- POJ 2421
- activity 代码中去掉背景
- IntentFilter
- java
- HDU 1421 搬寝室 (线性dp 贪心预处理)
- 网络IO之阻塞、非阻塞、同步、异步总结