zoukankan      html  css  js  c++  java
  • JavaSE第十天

    复习
    Object类的方法
    1.clone方法:克隆
      用法:implements Cloneable
            重写clone方法   public
      浅复制:复制引用变量的地址
      深复制:复制对象本身

    2.toSring方法:返回对象的字符串表示
      当打印对象时,默认调用
      默认值:包名.类名@hashCode

    3.equals方法:== 比较对象的地址

    4.hashCode方法:返回Integer的数
      如果equals方法返回true,hashCode相同。

    -------------------------------------------------
    String类
    1.final,不可以有子类

    2.String str = new String("hello");
      String str2 = "hello";

    3.字符串不可变
        final char[] value;

    4.StringBuilder  StringBuffer
       char[] value;

    5.方法:
    ----------------------------------------------------------
    正则表达式:表示字符串的判断条件
    phone:1[356789][0-9]{9}


    // 判断字符串:
    // 由3个字母组成
    // 第一个字母是a/b/c
    // 第二个字母是d/e/f/g
    // 第三个字母是x/y/z
    // System.out.println(str.matches("[abc][defg][xyz]"));

    // 匹配由一个字母组成的字符串
    // System.out.println(str.matches("[a-zA-Z]"));
    // 匹配由一个数字组成的字符串
    // System.out.println(str.matches("[0-9]"));
    // System.out.println(str.matches("\d"));

    // 匹配由一个字符组成的字符串,但不是a/b/c
    // [^...] 表示除了这些字符
    System.out.println(str.matches("[^abc]"));
    ------------------------------------------------
    // 匹配由a开头的由2个字符组成的字符串
    // . 表示通配符,可以匹配任意一个类型的字符
    // System.out.println(str.matches("a."));
    // 判断是否是一个 .
    // \. Java先转义为. ,正则再转义为.
    // System.out.println(str.matches("\."));
    // 怎么匹配 "c:\java"
    // \\ Java先转义为\ ,正则再转义为
    System.out.println(str.matches("\\"));
    -------------------------------------------
    // 数量词

    // + 表示之前的字符至少出现1次 >= 1
    // System.out.println(str.matches("a.+"));
    // 匹配由小写字母开头由数字结尾的字符串
    // * 表示之前的字符可有可无 >= 0
    // System.out.println(str.matches("[a-z].*\d"));
    // 匹配由a开头至多2个字符组成的字符串
    // ? 表示之前的字符至多出现1次 <= 1
    System.out.println(str.matches("a.?"));  a   ab
    -------------------------------------------
    // 匹配由5个小写字母组成的字符串
    // {n} 表示之前的字符恰好出现n次 == n
    // System.out.println(str.matches("[a-z]{5}"));acccc
    // 匹配至少由5个小写字母组成的字符串
    // System.out.println(str.matches("[a-z]{5,}"));
    // 匹配由8-12个小写字母组成的字符串
    System.out.println(str.matches("[a-z]{8,12}"));


    正则练习:
    1. 输入一个字符串,然后判断字符串是否是一个小数字符串
    10.28 0.56 3.00 13.85      15.  00.65
    2. 校验密码:8-20位,小写字母/大写字母/数字中的至少两种
    ------------------------------------------------------------
    //replaceAll()替换
        //"a   b    c"   \s  ""
        public static void test5(){
            String str = "a   b    c";
            String str2 = "abcqsbabc";
            System.out.println(str.replaceAll("\s", ""));
            System.out.println(str2.replaceAll("qsb", "*"));
        }
    //split()解析字符串
        //"0001 张三 18 100 99 100"
        public static void test6(){
            String stu = "0001 张三 18";
            String[] values = stu.split("\s");
            String name = values[1];
            int age = Integer.parseInt(values[2]);
            System.out.println(name+","+age);
            /*for(String str :values){
                System.out.println(str);
            }*/
        }

    ----------------------------------------------------------
    StringBuilder类
     可变字符串类:字符串内容改变频率高,建议使用此对象
      //不同对象的代码执行效率
      public static void main(String[] args) {
            String str = "a";
            long start = System.currentTimeMillis();
            for(int i = 1;i<=10000;i++){
                str+="b";
            }
            long end = System.currentTimeMillis();
            System.out.println(end-start);
            
            start = System.currentTimeMillis();
            StringBuilder str2 = new StringBuilder("a");
            for(int i = 1;i<=10000;i++){
                str2.append("b");
            }
            end = System.currentTimeMillis();
            System.out.println(end-start);
        }

    ------------------------------------------------------------
    8种基本数据的封装类
    byte short long float double boolean  ->首字母大写

    int - >  Integer
    char  - > Character


    Math类

    作者:赵瑞鑫。支持原创,从你我做起。
  • 相关阅读:
    【Salesfoece】Apex基础数据类型
    【Javascript】Redux ,Saga关系
    【CSS】选择器
    爬取取百度和Flickr图像
    hadoop系列之一问题锦集
    进行数据清洗_在进行大数据分析之前都需要进行数据清洗,如何进行数据清洗?...
    Hadoop中文编码乱码相关问题
    Can not find the tag library descriptor for "http://java.sun.com/jsp/jstl/
    解决:Multiple annotations found at this line:
    HttpServletRequest cannot be resolved to a type解决方案
  • 原文地址:https://www.cnblogs.com/Winer-Jiu/p/13419967.html
Copyright © 2011-2022 走看看