zoukankan      html  css  js  c++  java
  • 2016/5/29学习记录

    1.多态和动态绑定的例子,有助于理解

     1 public class Test {
     2     public static void main(String[] args) {
     3         new A();
     4         new B();
     5     }
     6 }
     7 
     8 class A {
     9     public int i = 7;
    10 
    11     public A() {
    12         setI(20);
    13         System.out.println("the number of i in A is " + i);
    14     }
    15 
    16     public void setI(int i) {
    17         this.i = 2 * i;
    18     }
    19 
    20 }
    21 
    22 class B extends A {
    23     public B() {
    24         System.out.println("the i in b is " + i);
    25     }
    26 
    27     public void setI(int i) {
    28         this.i = 3 * i;
    29     }
    30 }

    输出为

    the number of i in A is 40
    the number of i in A is 60
    the i in b is 60
    View Code

    2.ArrayList类的用法[对象列表/对象数组]

     ArrayList类包含的方法有+ArrayList()/+add()/+add(index,inti)/+clear/+contains/+get(intdex)/+indexOf(object)/+isEmpty()/+remove()/+set(index,inti)

     创建方式ArrayList<String> list = new ArrayList<> ();

     对ArrayList类可以使用遍历,这个和数组是一样的;

     从数组中创建对象列表{

      String[] array = new String[5];

      ArrayList<String> list = new ArrayList<>(Arrays.asList(array));  //这里使用了Arrays类的asList方法进行复制。

    }  

     反过来,从对象列表创建数组{

     ArrayList<String> list = new ArrayList<>();

     String[] b = new String[list.size()];

     list.toArray(b); 

    } 

     若数组里包含的是数值型的对象,可以进行排序如下

     Double [] array = {1.2,1,3,5.3,0.3};

     Arrays.sort(array);

     同样的对于对象列表 

     ArrayList<String> list = new ArrayList<>(Arrays.asList(array));

     java.util.Collections.sort(list);

     其中Collections有很多其他用法很方便。例如Collections.max(list)/Collections.min(list)/Collections.shuffle(list) //打乱 

      

     

  • 相关阅读:
    datatable linq查询操作filed用法
    C# asp.net 中sql like in 参数化
    c#.net全站防止SQL注入类的代码
    js面向对象编程:if中可以使用那些作为判断条件呢?
    HTTP Method 详细解读(`GET` `HEAD` `POST` `OPTIONS` `PUT` `DELETE` `TRACE` `CONNECT`)--转
    浅析HTTP代理原理--转
    细说Cookie--转
    HTTP协议7之Cookie--转
    HTTP协议6之状态码--转
    HTTP协议5之代理--转
  • 原文地址:https://www.cnblogs.com/laigaoxiaode/p/5540841.html
Copyright © 2011-2022 走看看