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


Java Stack.addElement方法代码示例

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


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

示例1: Mark

import java.util.Stack; //导入方法依赖的package包/类
/**
 * Constructor
 */
Mark(Mark other) {

    this.reader = other.reader;
    this.ctxt = other.reader.getJspCompilationContext();
    this.stream = other.stream;
    this.fileId = other.fileId;
    this.fileName = other.fileName;
    this.cursor = other.cursor;
    this.line = other.line;
    this.col = other.col;
    this.baseDir = other.baseDir;
    this.encoding = other.encoding;

    // clone includeStack without cloning contents
    includeStack = new Stack();
    for ( int i=0; i < other.includeStack.size(); i++ ) {
        includeStack.addElement( other.includeStack.elementAt(i) );
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:Mark.java

示例2: main

import java.util.Stack; //导入方法依赖的package包/类
public static void main(String[] args) {        
    
    Stack<Integer> stack = new Stack<>();
    System.out.println("init stack size: " + stack.size()+ ", capacity: "+ stack.capacity());
    
    // test if stack is empty
    System.out.println("Current stack isEmpty? " + stack.empty());
    
    // PUSH - Pushes the element onto the stack. Element is also returned.
    stack.push(3);
    stack.push(6);
    stack.push(4);
    System.out.println("Current stack size: " + stack.size()+", capacity: "+ stack.capacity()+ ", content: " + stack.toString());
    
    // first element, last element
    System.out.println("first element: " + stack.firstElement() + ", last element: " + stack.lastElement());
    
    // PEEK - Returns the element on the top of the stack, but does not remove it.
    System.out.println("Current top stack is " + stack.peek());
    
    // POP - Returns the element on the top of the stack, removing it in the process.
    System.out.println("Pop upper elemnent: " + stack.pop()+ ", current content: " + stack.toString());
    
    
    // add some element
    stack.add(1);
    stack.addElement(2);
    System.out.println("add element. Current stack content: " + stack.toString());
    
    // SEARCH - Searches for element in the stack. If found, 
    //          its offset from the top of the stack is returned. Otherwise,
    //          .1 is returned.        
    System.out.println("do 5 in the stack? " + stack.search(5));
    System.out.println("do 1 in the stack? " + stack.search(1));
    System.out.println("do 2 in the stack? " + stack.search(2));
    
    
    
}
 
开发者ID:mkdika,项目名称:learnjava8,代码行数:40,代码来源:TestStack.java


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