用代码演示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;
}
}

Java用代码演示String类中的以下方法的用法的更多相关文章

  1. 1.用代码演示String类中的以下方法的用法 (2018.08.09作业)

    public class Test_001 { public static void main(String[] args) { String a = "德玛西亚!"; Strin ...

  2. Java String类中的intern()方法

    今天在看一本书的时候注意到一个String的intern()方法,平常没用过,只是见过这个方法,也没去仔细看过这个方法.所以今天看了一下.个人觉得给String类中加入这个方法可能是为了提升一点点性能 ...

  3. Java——String类中的compareTo方法总结

    String类的定义:    java.lang  类 String   java.lang.Object      java.lang.String 所有已实现的接口:Serializable, C ...

  4. String类中的equals()方法:

    String类中的equals()方法: public boolean equals(Object anObject) { //如果是同一个对象 if (this == anObject) { ret ...

  5. 详解String类中的intern()方法

    我们用一个经典的例子来理解 package com.jvm.heap; public class MyTest { public static void main(String[] args) { S ...

  6. Java线程状态及Thread类中的主要方法

    要想实现多线程,就必须在主线程中创建新的线程对象. 不论什么线程一般具有5种状态,即创建,就绪,执行,堵塞,终止. 创建状态: 在程序中用构造方法创建了一个线程对象后,新的线程对象便处于新建状态,此时 ...

  7. String类中一些的方法的应用

    一.整理string类 1.Length():获取字串长度: 2.charAt():获取指定位置的字符: 3.getChars():获取从指定位置起的子串复制到字符数组中:(它有四个参数) 4.rep ...

  8. String类中的equals()方法

    在Java中,每一个对象都有一个地址空间,在这空间保存着这个对象的值. equals 比较的是值,==比较的地址以及值. 01: public class StringExample02: {03: ...

  9. Java中String类中常用的方法

    1.字符串与字符数组的转换 用toCharArray()方法将字符串变为字符数组 String str = "abcdef"; char c[] = str.tocharArray ...

随机推荐

  1. QNetworkAccessManager post()和get()方法

    GET方式提交的数据最多只能有1024字节,而POST则没有此限制. 大文件传输用post(),小文件用get(), 第一次接触Qt的Http项目,今天看了一下Post和Get的基本使用方法,就开始尝 ...

  2. 8.2.1.3 Range 优化

    range access method 方法使用单个索引去取回数据表的子集,它包含一个或多个索引值区间.Rang它能对单个部分索引或者多个部分索引使用.以下章节给出详细的描述 去解释怎么从where语 ...

  3. Linux:常用命令【转载】

    转载于:https://www.cnblogs.com/yjd_hycf_space/p/7730690.html 系统信息 arch 显示机器的处理器架构(1) uname -m 显示机器的处理器架 ...

  4. leetcode1014

    这道题暴力算法,会超时: class Solution(object): def maxScoreSightseeingPair(self, A: 'List[int]') -> int: n ...

  5. delphi 第三方组件 log4cpp.dll

    log4cpp.dll LogHelper.dll TcxGridSite TcxSpreadSheetBook TcxSpreadSheetBook TcxTreeList TcxButtonEdi ...

  6. 图文详解AO打印(端桥模式)(转)

    一.概述   AO打印是英文Active-Online Print的简称,也称主动在线打印.打印前支持AO通讯协议的AO打印机首先通过普通网络与C-Lodop服务保持在线链接,网页程序利用JavaSc ...

  7. zipfile模块

    在python中操作zip文件, 基本上都是使用zipfile模块,他可以创建.解压文件,获取zip文件的元数据信息. 我们想要操作一个zip文件,第一步就是初始化ZipFile实例. 1.打开tes ...

  8. input点击后的 默认边框去除

    转自 http://blog.sina.com.cn/s/blog_9f1cb4670102v47g.html css文件里加句话:*:focus { outline: none; } 或 input ...

  9. 焊接关节(Weld Joint)

    package{ import Box2D.Common.Math.b2Vec2; import Box2D.Dynamics.b2Body; import Box2D.Dynamics.Joints ...

  10. Spring AOP demo 和获取被CGLIB代理的对象

    本文分为两部分:1)给出Spring AOP的一个例子(会使用CGLIB代理):2)给出获取被CGLIB代理的原始对象. 1.Spring AOP Demo 这部分参考了博文(http://www.v ...