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. PyCharm自定义代码块设置方法-添加-删除【详细步骤】

    原文:https://blog.csdn.net/chichu261/article/details/82887108 在做项目的时候,有些代码会需要频繁的码.如果去已有的项目中去复制,又需要找很久. ...

  2. pytorch入坑一 | Tensor及其基本操作

    由于之前的草稿都没了,现在只有重写…. 我好痛苦 本章只是对pytorch的常规操作进行一个总结,大家看过有脑子里有印象就好,知道有这么个东西,需要的时候可以再去详细的看,另外也还是需要在实战中多运用 ...

  3. 有趣的一行 Python 代码

    https://mp.weixin.qq.com/s/o9rm4tKsJeEWyqQDgVEQiQ https://mp.weixin.qq.com/s/G5F_GaUGI0w-kugOZX145g ...

  4. H3C 不适当的VLAN间路由方式

  5. CSS多余文本省略号显示

    CSS多余文本省略号显示 本次案例代码是在 elementui 当中的 table 组件中实际需求 当然使用的是纯 CSS3 代码,所以原生支持度高,兼容性高,所以可多场景应用 对于过长文本进行单行省 ...

  6. 【31.95%】【CF 714B】Filya and Homework

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  7. 安卓中运行报错Error:Execution failed for task ':app:transformClassesWithDexForDebug'解决

    在androidstuio中运行我的未完项目,报错: Error:Execution failed for task ':app:transformClassesWithDexForDebug'.&g ...

  8. python OrderedDict

    15年16年接触python时候,还不知道这个函数,只知道dict的无序,造成了一些麻烦 今天view 代码,发现了 OrderedDict() 在python2.7中比较吃内存 pop(获取指定ke ...

  9. 服务发现之eureka

    一.什么是服务发现? 问题: 我们现在有多少个服务? 服务越来越多时,服务 URL 配置管理变得非常乱 服务对外的地址变了,其他所有有使用到的服务都要改地址 增加服务,增加服务实例等,都要做运维工作 ...

  10. http、https、SSL、TLS的区别

    一.HTTP和HTTPS之间的区别 HTTP是一种协议,全称叫作:超文本传输协议(HTTP,HyperText Transfer Protocol),是互联网上应用最为广泛的一种网络协议.所有的WWW ...