• java:常用类库api


     

     

     

     1 package com.vince;
     2 
     3 import java.util.Arrays;
     4 
     5 public class StringDemo2 {
     6 
     7     public static void main(String[] args) {
     8         
     9         String str = " fkwefwfa d6737383 ";
    10         char c = str.charAt(1);
    11         System.out.println(c);
    12         
    13         System.out.println(str.toCharArray());
    14         char[] cs = {'a','b','c'};
    15         String s1 = new String(cs);
    16         
    17         String s2 = new String(cs,0,1);
    18         System.out.println(s2);
    19         
    20         System.out.println(Arrays.toString(str.getBytes()));
    21         
    22         System.out.println(str.replace('w', '*'));
    23         System.out.println(str.replaceAll("\\d", "*"));
    24         
    25         System.out.println(str.substring(0, 4));
    26         
    27         System.out.println(Arrays.toString(str.split("d")));
    28         
    29         System.out.println(str.contains("a"));
    30         
    31         System.out.println(str.indexOf("f"));
    32         System.out.println(str.lastIndexOf("f"));
    33         System.out.println(str.isEmpty());
    34         
    35         System.out.println(str.length());
    36         
    37         System.out.println(str.trim());
    38         
    39         System.out.println(str.concat("*****"));
    40         System.out.println(String.valueOf(10));
    41     }
    42 
    43 }
    View Code

     


     

     

     

     

     

     


     

     

     1 package com.vince;
     2 
     3 /**
     4  * 对象需要具备克隆功能:
     5  * 1、实现Cloneable接口,(标记接口)
     6  * 2、重写Object类中的clone方法
     7  * @author vince
     8  * @description
     9  */
    10 public class Cat implements Cloneable{
    11     private String name;
    12     private int age;
    13     public String getName() {
    14         return name;
    15     }
    16     public void setName(String name) {
    17         this.name = name;
    18     }
    19     public int getAge() {
    20         return age;
    21     }
    22     public void setAge(int age) {
    23         this.age = age;
    24     }
    25     public Cat(String name, int age) {
    26         super();
    27         this.name = name;
    28         this.age = age;
    29     }
    30     public Cat() {
    31         super();
    32     }
    33     //重写Object中的clone方法
    34     @Override
    35     protected Object clone() throws CloneNotSupportedException {
    36         return super.clone();
    37     }
    38     @Override
    39     public String toString() {
    40         return "Cat [name=" + name + ", age=" + age + "]";
    41     }
    42     
    43 }
    Cat.java
     1 package com.vince;
     2 
     3 import java.io.IOException;
     4 
     5 public class Test {
     6 
     7     public static void main(String[] args) {
     8 
     9         Cat cat = new Cat("ίχίχΠʽ°Χ",2);
    10         try {
    11             Cat newCat = (Cat) cat.clone();
    12             
    13             
    14             System.out.println("cat="+cat);
    15             System.out.println("new cat="+newCat);
    16             System.out.println(cat==newCat);
    17         } catch (CloneNotSupportedException e) {
    18             e.printStackTrace();
    19         }
    20         
    21     }
    22 
    23 }
    Test.java


     

     


     

     

  • 相关阅读:
    Radmin View3.5
    delphi安装fastreport6
    大华监控设备配置文件导入生成工具
    大华监控和天地伟业监控免输密码登录助手
    锐捷交换机常用配置命令【加精】
    锐捷交换机的配置命令大全
    H3C常用配置命令
    锐捷交换机配置命令
    Delphi 随手笔记,使用了DEV控件组件
    读取软件的版本信息 GetFileVersionInfo
  • 原文地址:https://www.cnblogs.com/juham/p/15654503.html
Copyright © 2020-2023  润新知