zoukankan      html  css  js  c++  java
  • 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


     

     


     

     

  • 相关阅读:
    1014 Waiting in Line (30)(30 point(s))
    1013 Battle Over Cities (25)(25 point(s))
    1012 The Best Rank (25)(25 point(s))
    1011 World Cup Betting (20)(20 point(s))
    1010 Radix (25)(25 point(s))
    1009 Product of Polynomials (25)(25 point(s))
    1008 Elevator (20)(20 point(s))
    1007 Maximum Subsequence Sum (25)(25 point(s))
    1006 Sign In and Sign Out (25)(25 point(s))
    1005 Spell It Right (20)(20 point(s))
  • 原文地址:https://www.cnblogs.com/juham/p/15654503.html
Copyright © 2011-2022 走看看