zoukankan      html  css  js  c++  java
  • Java Q & A

    1. What is the difference between

    i.  List<Integer> list1 = new ArrayList<Integer>(Arrays.asList(ia));
    ii. List<Integer> list2 = Arrays.asList(ia); 
    i.  new ArrayList<Integer>(Arrays.asList(ia))
    • The new ArrayList is an independent copy of the original one.
    • Although you create the wrapper using Arrays.asList, it is used only during the construction of the new ArrayList and is garbage-collected afterwards.
    ii. Arrays.asList(ia)
    • Array ia and creates a wrapper that implements List<Integer>, which makes the original array as a list.
    • Nothing is copied at all, only a single wrapper object is created.
    • Operations on the list wrapper are propagated to the original array -- if you shuffle the list wrapper, the original array is shuffled; if you overwrite an element, it gets overwritten in the original array, etc.
    • Some List operations aren't allowed on the wrapper, like adding or removing elements from the list -- no resize.
    • list wrapper doesn't extend ArrayList -- ArrayLists have their own, internal array, which they are able to resize. 

    2. Contructor of PriorityQueue

    PriorityQueue(int initialCapacity, Comparator<? super E> comparator)

    initialCapacity shouldn't < 1, otherwise, there will be IllegalArgumentException. 

    3. 

  • 相关阅读:
    shell脚本sed的基本用法
    shell grep的基本用法
    禁止表单提示输入--autocomplete属性
    Cookie操作介绍
    JSP中的两种重定向
    SSM
    题解 P4994 【终于结束的起点】
    题解 P1286 【两数之和】
    题解 P2340 【奶牛会展】
    题解 CF450B 【Jzzhu and Sequences】
  • 原文地址:https://www.cnblogs.com/joycelee/p/5792235.html
Copyright © 2011-2022 走看看