Path: blob/master/test/jdk/java/util/ArrayList/AddAll.java
41149 views
/*1* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 471520626* @summary Ensure that addAll method can cope with underestimate by size().27* @author Josh Bloch28*/2930import java.util.ArrayList;31import java.util.LinkedList;32import java.util.List;33import java.util.Map;34import java.util.Vector;35import java.util.WeakHashMap;3637public class AddAll {38public static void main(String[] args) {39for (int j = 0; j < 1; j++) {40Map m = new WeakHashMap(100000);41for (int i = 0; i < 100000; i++)42m.put(new Object(), Boolean.TRUE);43new ArrayList().addAll(m.keySet());44}4546for (int j = 0; j < 1; j++) {47Map m = new WeakHashMap(100000);48for (int i = 0; i < 100000; i++)49m.put(new Object(), Boolean.TRUE);50new LinkedList().addAll(m.keySet());51}5253for (int j = 0; j < 1; j++) {54Map m = new WeakHashMap(100000);55for (int i = 0; i < 100000; i++)56m.put(new Object(), Boolean.TRUE);57new Vector().addAll(m.keySet());58}5960for (int j = 0; j < 1; j++) {61Map m = new WeakHashMap(100000);62for (int i = 0; i < 100000; i++)63m.put(new Object(), Boolean.TRUE);64List list = new ArrayList();65list.add("inka"); list.add("dinka"); list.add("doo");66list.addAll(1, m.keySet());67}6869for (int j = 0; j < 1; j++) {70Map m = new WeakHashMap(100000);71for (int i = 0; i < 100000; i++)72m.put(new Object(), Boolean.TRUE);73List list = new LinkedList();74list.add("inka"); list.add("dinka"); list.add("doo");75list.addAll(1, m.keySet());76}7778for (int j = 0; j < 1; j++) {79Map m = new WeakHashMap(100000);80for (int i = 0; i < 100000; i++)81m.put(new Object(), Boolean.TRUE);82List list = new ArrayList();83list.add("inka"); list.add("dinka"); list.add("doo");84list.addAll(1, m.keySet());85}86}87}888990