Copy ArrayDeque to an Array object Example

Copy ArrayDeque to an Array object Example


Posted in : Java Posted on : December 1, 2010 at 5:09 PM Comments : [ 0 ]

This Java Example shows how to copy all elements of ArrayDeque object to an Array object in java.

Copy ArrayDeque to an Array object Example

This Java Example shows how to copy all elements of ArrayDeque object to an Array object  in java. To copy the ArrayDeque elements to Array object we use Object[] toArray( ) method. This method returns an array containing all of the elements in this Deque in proper sequence.

 Example: ArrayDequecopytoArray.java

package devmanuals.com;

import java.util.*;

public class ArrayDequecopytoArray {

	public static void main(String args[]) {

		ArrayDeque ADeque = new ArrayDeque();
		ADeque.add("A");
		ADeque.add("B");
		ADeque.add("C");
		ADeque.add("D");
		System.out.println("The Array elements are :");
		Object[] obj = ADeque.toArray();
		for (int i = 0; i < obj.length; i++) {
			System.out.println(" " + obj[i]);
		}
	}
}

Output:

The Array elements are :
A
B
C
D

Download The Code

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics