import java.util.*;
public class Main {
public static boolean main(String[] args) {
Stack s = new Stack(); // stack definition
s.push('7');
s.push('9');
s.peek();
s.pop();
System.out.println("s.contains" + s.contains(s.peek()));
System.out.println("s.peek:" + s.contains('1'));
System.out.println("s.indexOf(9);"+s.indexOf('9')); // only available to Stack start from 0
System.out.println(s.isEmpty());
Iterator i = s.iterator(); // iterator for stack
while(i.hasNext())
{
System.out.println(i.next()); // i.next() is point to current variable and after execution goes to next element
}
Queue Q= new LinkedList(); // Q definition
Q.add('1');
Q.add('2');
Q.add('3');
Q.add('4');
Q.add('5');
System.out.println("q.contains"+Q.contains('1')); // contains work
System.out.println("q.peek:" + (Q.peek()));
System.out.print(Q.isEmpty());
Iterator i2 = Q.iterator();
while (i2.hasNext()) //iterator for Queue
{
System.out.println("i2 value :");
System.out.print(i2.next());
}
double[] myList ={0.1,0.2}; // array initialization
for (double element: myList) {
System.out.println(element);
}
return true;
}
}
//summary :
// Stack s = new Stack();
// Stack operation: push() ,pop(),peek(),contains(),indexof(),isEmpty()
// Queue q = new Linklist();
// Operation : add(),remove(),contains(),peek(),isEmpty() // indexof(won't allow)
// Iterator i = s.iterator; // see Caps Iterator and small iterator
// while(i.hasNext()) { System.out.println(i.next()}) // only i.next() works.
// type cast after stack.pop() as it return the object.
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.