zoukankan      html  css  js  c++  java
  • String

    package cn.lijun.demo2;

    public class StringDemo3 {
        public static void main(String[] args) {
            fun9();
        }
        //9  boolean  equals(Object obj);  判断字符串里面完全相等 返回true
        //s.equalsIgnoreCase(s1)  不区分大小写的比较
        public static void fun9(){
            String s = "hello";
            String s1= "hEllo";
            System.out.println(s.equals(s1));
            System.out.println(s.equalsIgnoreCase(s1));
            
        }
        //8 将字符串  转字符数组
        public static void fun8(){
            String s = "今晚11点老地方见 不见不散";
            char[] s1 = s.toCharArray();
            for (int i = 0; i < s1.length; i++) {
                System.out.println(s1[i]);
            }
            
        }
        //7 将字符串转字节数组  getBytes();
        
        public static void fun7(){
            String s = "今晚11点老地方见 不见不散";
            byte[] s1 = s.getBytes();
            //System.out.println(s1);
            for (int i = 0; i < s1.length; i++) {
                System.out.println(s1[i]);
            }
            
        }
        // 6 查找一个字符  indexOf(char ch)  返回int   返回-1 没有找到   
        public static void fun6(){
            String s = "hello.java";
            int s1 = s.indexOf('w');
            System.out.println(s1);
            
        }
        //5  contains判断一个字符串是否有另一个字符串
        
        public static void fun5(){
            String s = "hello.java";
            boolean s1 = s.contains("ll");
            System.out.println(s1);
        }
        //4判断一个字符串的后缀 结尾   endsWith("参数");
        public static void fun4(){
            String s = "hello.java";
            boolean s1 = s.endsWith(".java");
            System.out.println(s1);
        }
        //3boolean statsWith(String preFix)  判断一个字符串是否包含另一个字符串
        public static void fun3(){
            String s = "helloworld";
            boolean s1 = s.startsWith("hello");
            System.out.println(s1);
        }
        //2 substring(int beginIndex,int endIndex)获取字符串的一部分 包含头 不包含尾
        //substring(int beginIndex)  后面的全要
        
        public static void fun2(){
            String s = "helloworld";
            String s2 = s.substring(2);
            //String s1 = s.substring(1, 4);
            System.out.println(s2);
        }
        // 1 int length();  返回的是字符串的长度
        public static void fun1(){
            String string = "skjl";
            int l = string.length();
            System.out.println(l);
        }
    }

  • 相关阅读:
    P1030 求先序排列 P1305 新二叉树
    spfa
    Clairewd’s message ekmp
    Cyclic Nacklace hdu3746 kmp 最小循环节
    P1233 木棍加工 dp LIS
    P1052 过河 线性dp 路径压缩
    Best Reward 拓展kmp
    Period kmp
    Substrings kmp
    Count the string kmp
  • 原文地址:https://www.cnblogs.com/hsx1996/p/10556405.html
Copyright © 2011-2022 走看看