1.字符串与字符数组的转换

用toCharArray()方法将字符串变为字符数组

String str = "abcdef";

char c[] = str.tocharArray();

2.从字符串中取出指定位置的字符

String str = "abcdef"

System.out.println(str.charAt(x));    //x为第几个字符

3.字符串与byte数组的转换

String str = "abcdef";
byte c[] = str.getBytes();

4.取得一个字符串的长度

Srting str = "abcdef";

System.out.print(str.length);

5.查找一个字符串是否存在

String str = "abcdef";

System.out.print(str.indexOf("i"));     //i为字符,即查到指定字符位置

String str = "abcdef";

if(str.contains("i"))
{ System.out.print("存在这个字符");
}

6.去掉左右空格

String str = " abcdef ";

System.out.print(str.tirm());

7.字符串截取

String str = "abcdef";

System.out.print(str.substring(i));  //i表示从那个位置开始截取,为数字

System.out.print(str.substring(,));  //表示从0-5截取

8.按照指定的字符串拆分字符串

String str = "abcdef";

String c[] = str.split("i");   //i表示要拆分的内容

for(int i=;i<c.length;i++)    //输出拆分的内容
{
System.out.println(c[i]);
}

9.字符串大小写转换

”要转换的内容“.toUpperCase;              小写转换大写
”要转换的内容“.toLowerCase; 大写转换小写

10.判断是否以指定的字符串开头或者结尾

if(str.startsWith("i"))            //i为指定的内容
{
System.out.println("以i结尾")
} if(str.endsWith("i"))
{
System.out.println("以i开头");
}

11.不区分大小写进行字符串比较

equals      //这个比较是区分大小写的

equalslgnoreCase   //这个比较是不区分大小写的

12.将一个指定的字符串,替换成其他的字符串

String str = "abcdef";     

String newstr = str.replaceAll("c","d");     //将所有的c换成d

System.out.println(newstr);

最新文章

  1. WCF基础教程之异常处理:你的Try..Catch语句真的能捕获到异常吗?
  2. NHibernate概念
  3. [渣译文] 使用 MVC 5 的 EF6 Code First 入门 系列:为ASP.NET MVC应用程序更新相关数据
  4. yii2 使用twig 模板引擎
  5. 创建一个弹出DIV窗口
  6. 【PL/SQL练习】控制结构
  7. C++ 程序在运行时不显示dos界面
  8. Json,Gson,Ajax基础知识
  9. 10分钟理解JS引擎的执行机制
  10. Linux &quot;ls -l&quot;文件列表权限详解 【转】
  11. Java集合性能分析-疯狂Java讲义
  12. Python lambda介绍
  13. Redis无法启动
  14. linux 安装python3 date更新
  15. PS合成的5个要点:场景、对比、氛围、模糊、纹理
  16. oracle创建表空间,表及用户
  17. javax.mail 发送邮件 , greenMail 测试 , spring
  18. 【译】第八篇 SQL Server代理使用外部程序
  19. 关于Unity启动时间过长(启动黑屏时间长)的问题!!! 牛逼... 思路不错...
  20. 菜鸟进阶之:VC++之Visual Studio中DLL调用实现

热门文章

  1. uoj218_火车管理
  2. help_topic表,以字符拆分,一行转多行
  3. python多线程之threading、ThreadPoolExecutor.map
  4. [ERROR] Failed to execute goal org.apache.maven.plugins:maven-install-plugin:2.4:install (default-cli) on project kircp-js-plan-resource: The packaging for this project did not assign a file to the bu
  5. mysql个人初配置
  6. passwd 修改用户密码 / chpasswd 批量更新用户密码
  7. [USACO12FEB]牛券Cow Coupons(堆,贪心)
  8. ROPE
  9. Java并发编程实战 第15章 原子变量和非阻塞同步机制
  10. LAMP 系统性能调优之网络文件系统调优