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);
        }
    }

  • 相关阅读:
    从程序员转向项目经理
    LLBL Gen Template Studio 2.x
    抛弃强大的TFS ,借助于BugTracker.NET + Visual Source Safe + SourceLink搭建项目开发环境
    Entity Framework 5中应用表值函数进行Linq查询
    SQL Server 2012 T-SQL 新特性
    当你还在纠结于ORM的性能时,我已经远远的把你抛在脑后
    直接修改.NET程序集 LLBL Gen 2.x-4.x 许可授权方法研究
    企业应用开发模式 ERP项目中应用到的技术和工具
    Enterprise Solution 应用程序开发框架培训
    架构:小议应用开发平台
  • 原文地址:https://www.cnblogs.com/hsx1996/p/10556405.html
Copyright © 2011-2022 走看看