Answer:
import java.util.*;
import java.lang.*;
import java.io.*;
class Codechef
{
public static void main (String[] args)
{
Stack<Integer> mat=new Stack<Integer>();
mat.add(1);
mat.add(3);
mat.add(6);
System.out.println(mat);
Object [] a=mat.toArray();
for(int i=0;i<a.length;i++)
System.out.println(a[i]);
}
}
Explanation:
An integer type stack st is created;
1,3 and 6 are added to the stack.
printing the contents of the stack.
array a is created form the stack using toArray().
Then printing the array.