用代码演示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. android 开发 修改系统背景(状态栏颜色、导航栏颜色、标题栏颜色等等)

    1.打开values下的styles.xml 发现有以下代码: <resources> <!-- Base application theme. --> <style n ...

  2. SQL Server Url Decode函数

    )) ) AS BEGIN ), ), ) SET @count = Len(@url) SET @urlReturn = '' WHILE (@i <= @count) BEGIN ) IF ...

  3. Django之视图Views

    视图 视图接受Web请求并且返回Web响应 视图就是一个python函数,被定义在views.py中 响应可以是一张网页的HTML内容,一个重定向,一个404错误等等 响应处理过程如下图: URLco ...

  4. yii主题

    修改应用的配置文件(protected/config/main.php)中加入 return array( ’theme’=>’basic’, ); 所有的视图文件必须位于views下 ,布局视 ...

  5. dubbo 学习资料

    入门: http://www.tuicool.com/articles/FnE3em http://www.cnblogs.com/xuyatao/p/6869231.html 最好 http://w ...

  6. 在集群上运行Spark

    Spark 可以在各种各样的集群管理器(Hadoop YARN.Apache Mesos,还有Spark 自带的独立集群管理器)上运行,所以Spark 应用既能够适应专用集群,又能用于共享的云计算环境 ...

  7. 3. group_concat与oracle中wm_concat用法一样

    例子如下: select group_concat(rp.ROLE_ID) from eic_right_role_operator rp where rp.OPERATOR_ID = #id#

  8. leetcode1013

    class Solution(object): def canThreePartsEqualSum(self, A: 'List[int]') -> bool: n = len(A) sums ...

  9. Mysql IN语句查询

    语法: WHERE column IN (value1,value2,...) WHERE column NOT IN (value1,value2,...) 1.in 后面是记录集,如: selec ...

  10. VC 字符串转化和分割

    原文:点击这里. 备忘:为了适用于Unicode环境,要养成使用_T()宏的习惯 1.格式化字符串 CString s;s.Format(_T("The num is %d."), ...