zoukankan      html  css  js  c++  java
  • String笔记02

    string02

    字符串的获取相关方法

     /*
     1.public int length ();获取字符串当中含有的字符个数,拿到字符串的长度
     2.public String concat (String str) 将当前字符串和参数字符串拼接成为新字符串
     3.public char charAt(int index) 获取指定索引位置的单个字符
     4.public int indexof (String str)查找参数字符串在本字符串当中首次出现的索引位置,若没有返回-1
      */
     public class PracticeString02 {
     
         public static void main(String[] args) {
     
             String str1 = "wrhvjsvnbbsbv";
             int length = str1.length();
             System.out.println("str1的长度为:"+length);
     
             String str2 = "fff ";
             String str3 = str2.concat(str1);
             System.out.println(str3);
     
             char ch = str1.charAt(5);
             System.out.println(ch);
     
             String str4 = "sv";
             int n = str3.indexOf(str4);
             System.out.println(n);
     
        }
     }

    字符串的截取和分割相关方法

     /*
     字符串的截取方法
     1.public String substring (int index)截取从参数位置一直到字符串末尾,返回新字符串;
     2.public String substring (int begin,int end)截取从begin开始,一直到end结束中间的字符串
      */
     public class PracticeString03 {
         public static void main(String[] args) {
     
             String str1 = "Hellow,world";
             String str2 =str1.substring(7);
             System.out.println(str2);//world
     
             String str3 = str1.substring(5,8);//[begin,end),w,w
             System.out.println(str3);
     
             /*
             字符串的分割方法
             public String split (String regex)按照参数的规则,将字符串切成若干部分
             ps:若按照英文句点“."切分 ,参数必须写”\.“
              */
             String[]  astr= str1.split("o");
             for (int i = 0; i < astr.length; i++) {
                 System.out.println(astr[i]);
            }//hell w,w, rld
     
        }
     }

    字符串的转换相关方法

    /*
    字符串的转换
    public cahr[] toCharArray();将当前字符串拆分成字符数组作为返回值
    public byte[] getBytes();获得当前字符串底层的字节数组
    public String replace(charSequence old,charSequence new)用新字符串替换老字符串,返回新字符串
    */
    public class PracticeString04 {
    public static void main(String[] args) {

    String str1 = "hiuytreq";
    char[] arr = str1.toCharArray();
    for (int i = 0; i < arr.length; i++) {
    System.out.println(arr[i]);
    }

    byte[] bbb = str1.getBytes();
    for (int i = 0; i <bbb.length ; i++) {
    System.out.println(bbb[i]);
    }

    String str2 = "you,are,sbs";
    String str3 = str2.replace("sb","good");
    System.out.println(str3);

    }
    }

  • 相关阅读:
    ldap集成jenkins
    自动发现实现url+响应时间监控
    5秒跳转
    String的使用
    数字货币转换为中文货币
    字符串的使用(string,StringBuffer,StringBuilder)
    修饰符
    类的继承,抽象类,接口,方法重写和重载
    类的使用
    java中的输入流(Scanner),数据类型,运算符,switch,数组的用法
  • 原文地址:https://www.cnblogs.com/susexuexi011/p/13746537.html
Copyright © 2011-2022 走看看