用代码演示String类中的以下方法的用法
(1)boolean isEmpty(): 判断字符串是不是空串,如果是空的就返回true
(2)char charAt(int index): 返回索引上的字符
(3)String toLowerCase(): 字符串转成小写
(4)String toUpperCase(): 字符串转成大写
(5)String repalce(char oldChar, char newChar): 将字符串中的老字符,替换为新字符
(6)String repalce(String old, String newstr): 将字符串中的老字符串,替换为新字符串
(7)String trim(): 去掉字符串两端空格

代码如下:

 package com.aaa.zuoye;

 public class ZuoYe {
public static void main(String[] args) {
fun7();
}
// (7)String trim(): 去掉字符串两端空格
public static void fun7(){
String str=" helloword ";
str=str.trim();
System.out.println(str);
}
// (6)String repalce(String old, String newstr): 将字符串中的老字符串,替换为新字符串
public static void fun6(){
String str="hellohaini";
str=str.replaceFirst("h", "1");
System.out.println(str);
}
// (5)String repalce(char oldChar, char newChar): 将字符串中的老字符,替换为新字符
public static void fun5(){
String str="hello";
str=str.replace("o", "a");
System.out.println(str);
}
// (4)String toUpperCase(): 字符串转成大写
public static void fun4(){
String str="hellO";
System.out.println(str.toUpperCase());
}
// (3)String toLowerCase(): 字符串转成小写
public static void fun3(){
String str1="helloWord";
System.out.println(str1.toLowerCase());
}
// (2)char charAt(int index): 返回索引上的字符
public static void fun2(){
String str1="helloWord";
System.out.println(str1.charAt(2));
}
//(1)boolean isEmpty(): 判断字符串是不是空串,如果是空的就返回true
public static boolean fun1(){
String str1="";
if(str1.isEmpty()==true){
return true;
}
return false;
}
}

最新文章

  1. thoughtworks编程题
  2. Java新集合示意图
  3. u3d单词学习plane
  4. Java ArrayListSerialise
  5. docker stop 与 docker kill的区别
  6. discuz 门户栏目URL跳转异常的问题
  7. hihoCoder挑战赛14 A,B,C题解
  8. Android判断应用程序从后台回到前台
  9. Python challenge 3 - urllib & re
  10. [转]解决VS2008 开发Windows Mobile 项目生成速度慢的问题
  11. NOIP2014-普及组复赛-第二题-比例简化
  12. devexpress表格控件gridcontrol图片列,按钮列,时间列等特殊列的实现
  13. Rails 定时任务——whenever实现周期性任务
  14. jmeter导入DB数据再优化
  15. 在 Ubuntu14.04 上搭建 Spark 2.3.1(latest version)
  16. spring 整合junit进行测试
  17. Hadoop简单介绍
  18. 玩转spring boot——war部署
  19. QT开发之旅四邮件发送工具
  20. CEF之CefSettings设置日志等级

热门文章

  1. sqlserver 导入导出
  2. oracle 问题
  3. 18.纯 CSS 创作 404 文字变形为 NON 文字的交互特效
  4. 如何删除GitHub中已经建好的仓库(repository)
  5. 键值对操作 之 combineByKey
  6. php单图片上传。
  7. View Stack容器,按钮选择子容器
  8. xml文件中的${}
  9. linux中根据进程的PID值来查找执行文件的及其路径
  10. js判断网页是否加载完毕