String类的判断功能:

boolean equals(Object obj)  //比较字符串内容是否相同(区分大小写)。

boolean equalsIgnoreCase(String str)  // 不区分大小写。

boolean contains(String str) // 判断当前字符串中是否包含参数内容。

boolean startsWith(String str) //判断当前字符串对否以参数字符串开头。

boolean endsWith(String str) // 判断当前字符串是否已参数字符串结尾。

boolean isEmpty() //判断空字符串 “”。

 public class StringDemo {
   public static void main(String[] args) {
     //boolean equals(Object obj)

     String s = "helloworld";
     System.out.println(s.equals("Helloworld"));

     //不区分大小写的相等比较
     System.out.println(s.equalsIgnoreCase("Helloworld"));

     //boolean contains(String str) // 判断当前字符串中是否包含参数内容
     String s1 = "wnagdao";
     String s2 = "gd";
     System.out.println(s1.contains(s2));

     //boolean startsWith(String str) //判断当前字符串对否以参数字符串开头
     String s3 = "wn";
     System.out.println(s1.startsWith(s3));

     //boolean endsWith(String str) // 判断当前字符串是否已参数字符串结尾
     String s4 = "ao";
     System.out.println(s1.endsWith(s4));

     //boolean isEmpty() //判断空字符串 “”  null
     String s5 = "";
     System.out.println(s5.isEmpty());

     //int a = ' ';
     //System.out.println(a);

   }

 }

String类的的获取功能:

对于所有的下标位置而言: 从0开始递增 > 0

通常对于查找而言 -1表示没找到。

int  length()    // 当前字符串中包含的字符序列中的字符个数。

char charAt(int index) // 返回当前字符串对象中某个位置的字符“abc”。

int indexOf(int ch) //返回 某个字符在当前字符串中首次出现的位置。

int indexOf(String str) //查找参数字符串,当前字符串中首次出现的位置。

int indexOf(int ch,int fromIndex)

// 从当前字符串的某个位置开始(包含这个位置),向后查找参数字符首次出现的位置。

int indexOf(String str,int fromIndex)

//从当前字符串的某个位置开始(包含这个位置),向后查找参数字符串首次出现的位置。

String substring(int start)

//返回当前字符串从某个位置开始一直到结束的子串(不会改变原字符串)。

String substring(int start,int end) // 从[start, end)位置的当前字符串的子串。

 public class StringDemo {
   public static void main(String[] args) {
     //int  length()
     // 当前字符串中包含的字符序列中的字符个数
     String s1 = "atm";
     System.out.println(s1.length());

     // char charAt(int index)
     // 返回当前字符串对象中某个位置的字符  “abc”
     String s2 = "yuzhoutiao";
     System.out.println(s2.charAt(4));

     //int indexOf(int ch)
     // 返回 某个字符在当前字符串中首次出现的位置
     String s3 = "absca";
     System.out.println(s3.indexOf('a'));

    // int indexOf(int ch,int fromIndex)
     // 从当前字符串的某个位置开始(包含这个位置),
     // 向后查找参数字符首次出现的位置
     System.out.println(s3.indexOf('a', 1));

     //int indexOf(String str,int fromIndex)
     String s4 = "sc";
     System.out.println(s3.indexOf(s4));
     System.out.println(s3.indexOf(s4, 3));

     // String substring(int start)
     String s5 = "abcedef";
     System.out.println(s5.substring(2));//cedef

     //String substring(int start,int end) [start, end)
     System.out.println(s5.substring(1, s5.length() - 1)); //bcede
   }
 }
 /*
    删除功能
     public StringBuffer deleteCharAt(int index)
     public StringBuffer delete(int start,int end) [start, end)

     替换功能
     // 用所给字符串,替换掉字符缓冲区中,指定范围的字符串虚列
     public StringBuffer replace(int start,int end,String str)

     反转功能
     public StringBuffer reverse()  //反转字符缓冲区中的字符序列
  */
 public class StringOtherapi {

   public static void main(String[] args) {
     String s = "zhang";
     StringBuffer stringBuffer = new StringBuffer(s);
     //测试删除字符
     StringBuffer stringBuffer1 = stringBuffer.deleteCharAt(s.length() - 1);
     System.out.println(stringBuffer1.toString());

     //测试删除某个[start, end)
     StringBuffer delete = stringBuffer.delete(2, s.length());
     System.out.println(delete.toString());

     //替换功能
     StringBuffer abcd = stringBuffer.replace(0, 2, "abcd");
     System.out.println(abcd.toString());

     //测试字符串反转
     String str = reverseStr("abcd");
     System.out.println(str);

     //测试一下
     str = "hansh";
     StringBuffer stringBuffer1 = new StringBuffer(str);
     System.out.println(stringBuffer1.reverse().toString());

     String path = "/zs/web/file";
     String[] split = path.split("/");

     for (int i = 0; i < split.length; i++) {
       System.out.println(split[i]);
     }

   }

   public static String reverseStr(String s) {
     char[] tmp = new char[s.length()];

     int length = s.length();
     for (int i = 0; i < length; i++) {
       char c = s.charAt(i);
       tmp[length - 1 - i] = c;
     }
     return new String (tmp);
   }

 }

String类的转化功能:

byte[] getBytes()  //返回当前字符串中字符序列所代表的byte[]。

char[] toCharArray() //返回当前字符串中字符序列的字符数组。

static String valueOf(char[] chs) //将字符数组转化成对应的字符串。

static String valueOf(int i) // 把整数表示为其字符串表示形式 1 “1”。

String toLowerCase()  //把字符串转化为小写。

String toUpperCase()  //把字符串转化为大写。

String concat(String str) //字符串连接。

 public class StringDemo {
   public static void main(String[] args) {
     //byte[] getBytes()  //返回当前字符串中字符序列所代表的byte[]
     String s = "abc";
     System.out.println(Arrays.toString(s.getBytes())); //[B@4554617c

     // char[] toCharArray() //返回当前字符串中字符序列的字符数组
     System.out.println(Arrays.toString(s.toCharArray()));

     //static String valueOf(char[] chs) //将字符数组转化成对应的字符串
     char[] chars = {'a', 'b', 'c', 'd'};
     String s1 = String.valueOf(chars);
     System.out.println(s1);

     //static String valueOf(int i)
     System.out.println(String.valueOf(1) + 1);
     System.out.println(String.valueOf(new StringDemo()));
     System.out.println(String.valueOf(3.3) + 1);

     //String toLowerCase()
     String s2 = "ABcdEF";
     System.out.println(s2.toLowerCase());
     System.out.println(s2.toUpperCase());

     //String concat(String str) //字符串连接
     System.out.println(s2.concat("lalala"));
   }
 }
 String类的替换功能:
 String replace(char old,char new)
 //用新字符替换字符串中所有旧字符。
 String replace(String old,String new)
 // 用新的字符串内容替换所有旧的字符串内容。
 String类去除空字符串。
 String trim()

 String类的比较功能:
 int compareTo(String str)
 int compareToIgnoreCase(String str)
 接口:
 Comparable { //比较大小的协议
        int  compareTo(Object obj);
      }
    compareTo方法 返回值是 负数  代表当前对象 < 待比较对象
                          0    代表两个对象 ==
                         正数   当前对象    > 待比较对象

String类方法的使用的更多相关文章

  1. String类方法

    1.charAt(int index)  返回指定索引处的 char 值. 2. length() 返回此字符串的长度. 3.String replace(char oldChar, char new ...

  2. java学习之路--String类方法的应用

    消除字符串两端的空格 1.判断字符串第一个位置是否为空格,如果是继续向下判断,直到不是空格位置,末尾也是这样,往前判断,直到不是空格为止. 2.当开始和末尾都不是空格时,获取字符串. public s ...

  3. 【实用类String】String类方法的应用案例:查找判断指定字符出现的次数和位置

    一.应用要求 输入一个字符串,再输入要查找的字符,判断该字符在该字符串中出现的次数. 二.实现思路 1.使用substring()方法将字符串的每个字符存入数组 2.比较数组每个字符是否与指定的字符相 ...

  4. SummerVocation_Learning--java的String类方法总结

    壹: public char charAt(int index),返回字符串中第index个字符. public int length(), 返回字符串长度. public int indexOf(S ...

  5. AJPFX关于部分String类方法

    string类使用于描述字符串事物常见的操作:1.获取:  1.1 字符串中的包含的字符数,也就是字符串的长度        int length():获取字符串的长度 1.2 根据位置获取位置上的某 ...

  6. 原生JS:String对象详解

    @import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...

  7. String类详解(1)

    首先String是一个类. 1,实例化String类方法. 1)直接赋值:String name="haha"; 2)通过关键字:String name=new String(&q ...

  8. c#语言基础编程—string

    引言 在c#中经常会有相关的string的操作,string类型为引用类型,集成于Object,所以会有四个方法.详情可见 值类型和引用类型的区别 里面详细介绍了,值类型和引用类型的区别和应用场合,所 ...

  9. java中String类型的相关知识

    String类方法整理说明: ·Length()用来求字符串的长度,返回值为字符串的长度: ·charAt()取该字符串某个位置的字符,从0开始,为char类型: ·getChars()将这个字符串中 ...

随机推荐

  1. 【t065】最敏捷的机器人

    Time Limit: 1 second Memory Limit: 128 MB [问题描述] [背景] Wind设计了很多机器人.但是它们都认为自己是最强的,于是,一场比赛开始了~ [问题描述] ...

  2. TabHost选项卡的实现(一):使用TabActivity实现

    一. TabHost的基本开发流程 TabHost是一种非常实用的组件,可以很方便的在窗口上防止多个标签页,每个标签页相当于获得了一个外部容器相同大小的组件摆放区域. 我们熟悉的手机电话系统" ...

  3. Python--day32--ftp文件传输报错的原因

    解决办法:把buffer改小 server.py #实现一个大文件的上传或下载 #配置文件 ip地址 端口号 import json import socket import struct sk = ...

  4. P1099 双连击

    题目描述 我们假设一个二位整数 \(N(10 \le N \le 99)\) ,它的十位上的数字是 \(A\) ,个位上的数字是 \(B\) ,如果 \(A\) 和 \(B\) 的比例关系满足 \(A ...

  5. win10 uwp 发布旁加载自动更新

    在很多企业使用的程序都是不能通过微软商店发布,原因很多,其中我之前的团队开发了很久的应用,结果发现没有用户能从微软应用商店下载所以我对应用商店没有好感.但是作为一个微软粉丝,怎么能不支持 UWP 开发 ...

  6. C# json 转 xml 字符串

    本文告诉大家如何将 json 转 xml 或将 xml 转 json 字符串 首先需要安装 Newtonsoft.Json 库,打开 VisualStudio 2019 新建一个 dotnet cor ...

  7. H3C FTP其他常用命令

  8. 将url传参的中文字符在页面中显示正常

    //将url传参的中文字符在页面中显示正常var url=decodeURI(url);

  9. springboot多对一关系映射

    原文:https://blog.csdn.net/h993438890/article/details/89146483 spring boot项目的创建省略创建两张表t_user 字段 主键id,u ...

  10. 2018-8-10-win10-uwp-按下等待按钮

    title author date CreateTime categories win10 uwp 按下等待按钮 lindexi 2018-08-10 19:16:50 +0800 2018-2-13 ...