当前位置: 首页>>代码示例>>Java>>正文


Java ArrayDeque.removeFirst方法代码示例

本文整理汇总了Java中java.util.ArrayDeque.removeFirst方法的典型用法代码示例。如果您正苦于以下问题:Java ArrayDeque.removeFirst方法的具体用法?Java ArrayDeque.removeFirst怎么用?Java ArrayDeque.removeFirst使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.ArrayDeque的用法示例。


在下文中一共展示了ArrayDeque.removeFirst方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import java.util.ArrayDeque; //导入方法依赖的package包/类
public static void main(String[] args) {
    HashMap<Integer, Integer> map = new HashMap<>();
    ArrayDeque<Integer> deque     = new ArrayDeque<>();
    
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int m = scan.nextInt();
    int max = 0;
    
    for (int i = 0; i < n; i++) {
        /* Remove old value (if necessary) */
        if (i >= m) {
            int old = deque.removeFirst();
            if (map.get(old) == 1) {
                map.remove(old);
            } else {
                map.merge(old, -1, Integer::sum);
            }
        }
        
        /* Add new value */
        int num = scan.nextInt();
        deque.addLast(num);
        map.merge(num, 1, Integer::sum);
        
        max = Math.max(max, map.size());
    }
    
    scan.close();
    System.out.println(max);
}
 
开发者ID:MohamedSondo,项目名称:ACE_HackerRank,代码行数:32,代码来源:Solution.java

示例2: testEmpty

import java.util.ArrayDeque; //导入方法依赖的package包/类
/**
 * isEmpty is true before add, false after
 */
public void testEmpty() {
    ArrayDeque q = new ArrayDeque();
    assertTrue(q.isEmpty());
    q.add(new Integer(1));
    assertFalse(q.isEmpty());
    q.add(new Integer(2));
    q.removeFirst();
    q.removeFirst();
    assertTrue(q.isEmpty());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:ArrayDequeTest.java

示例3: testSize

import java.util.ArrayDeque; //导入方法依赖的package包/类
/**
 * size changes when elements added and removed
 */
public void testSize() {
    ArrayDeque q = populatedDeque(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(SIZE - i, q.size());
        q.removeFirst();
    }
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(i, q.size());
        q.add(new Integer(i));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:ArrayDequeTest.java

示例4: testRemoveFirst

import java.util.ArrayDeque; //导入方法依赖的package包/类
/**
 * removeFirst() removes first element, or throws NSEE if empty
 */
public void testRemoveFirst() {
    ArrayDeque q = populatedDeque(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(i, q.removeFirst());
    }
    try {
        q.removeFirst();
        shouldThrow();
    } catch (NoSuchElementException success) {}
    assertNull(q.peekFirst());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:ArrayDequeTest.java

示例5: testRetainAll

import java.util.ArrayDeque; //导入方法依赖的package包/类
/**
 * retainAll(c) retains only those elements of c and reports true if changed
 */
public void testRetainAll() {
    ArrayDeque q = populatedDeque(SIZE);
    ArrayDeque p = populatedDeque(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        boolean changed = q.retainAll(p);
        assertEquals(changed, (i > 0));
        assertTrue(q.containsAll(p));
        assertEquals(SIZE - i, q.size());
        p.removeFirst();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:ArrayDequeTest.java

示例6: loadModulesFromList

import java.util.ArrayDeque; //导入方法依赖的package包/类
/**
 * Loads modules (and their dependencies) specified in the list
 * @param configMods The fully-qualified module names
 * @return The ModuleContext containing all the loaded modules
 * @throws FloodlightModuleException
 */
public synchronized IFloodlightModuleContext
        loadModulesFromList(Collection<String> configMods,
                            Properties prop)
                                    throws FloodlightModuleException {
    logger.debug("Starting module loader");

    findAllModules(configMods);

    ArrayList<IFloodlightModule> moduleList = new ArrayList<>();
    Map<Class<? extends IFloodlightService>, IFloodlightModule> moduleMap =
            new HashMap<>();
    HashSet<String> modsVisited = new HashSet<>();

    ArrayDeque<String> modsToLoad = new ArrayDeque<>(configMods);
    while (!modsToLoad.isEmpty()) {
        String moduleName = modsToLoad.removeFirst();
        traverseDeps(moduleName, modsToLoad,
                     moduleList, moduleMap, modsVisited);
    }

    parseConfigParameters(prop);

    loadedModuleList = moduleList;

    initModules(moduleList);
    if(startupModules)
        startupModules(moduleList);

    return floodlightModuleContext;
}
 
开发者ID:xuraylei,项目名称:fresco_floodlight,代码行数:37,代码来源:FloodlightModuleLoader.java


注:本文中的java.util.ArrayDeque.removeFirst方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。