Search Java Code Snippets


  Help us in improving the repository. Add new snippets through 'Submit Code Snippet ' link.





#Java - Code Snippets for '#Stack' - 4 code snippet(s) found

 Sample 1. Write a Program to implement stack using an array

public class Stack{
static int top = 0;
static Element[] stack = new Element[10];

static class Element {
int body;

Element(int value){
body = value;
}
}

public static void main(String[] args){
push(5);
System.out.println(top);
push(7);
System.out.println(top);
poll();
System.out.println(top);
poll();
System.out.println(top);
}

private static void push(int value){
Element newElement = new Element(value);
top++;
}

private static Element poll(){
Element topElement = stack[top];
top--;
return topElement;
}
}

   Like      Feedback     stack


 Sample 2. Usage of Java Collections Stack

Stack<INodeDirectory> directories = new Stack<INodeDirectory>();
for(directories.push((INodeDirectory)inode); !directories.isEmpty(); ) {
   INodeDirectory d = directories.pop();
}

   Like      Feedback     stack  collections  java.util


 Sample 3. Printing Stack trace using Apache Commons ExceptionUtils

try {

} catch (Exception ex){
   System.out.println(ExceptionUtils.getFullStackTrace(ex));
}

   Like      Feedback     Apache Commons ExceptionUtils  Apache commons


 Sample 4. Code Sample / Example / Snippet of org.apache.bcel.classfile.StackMap

    public Attribute copy( final ConstantPool _constant_pool ) {

final StackMap c = (StackMap) clone();

c.map = new StackMapEntry[map.length];

for (int i = 0; i < map.length; i++) {

c.map[i] = map[i].copy();

}

c.setConstantPool(_constant_pool);

return c;

}


   Like      Feedback      org.apache.bcel.classfile.StackMap



Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner