212k views
5 votes
Create a stack with three integers and then use .toarray to copy it to an array.

1 Answer

1 vote

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]);

}

}

Step-by-step 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.

User BotanMan
by
5.8k points