當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。