Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML


 
  
 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 

 
Facing Programming Problem?
Ask Questions?, Browse Latest Questions, Question-Answer Guidelines
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

Collection to Array

                         

The example given below illustrates the conversion of  a collection into a array. In this example we creating an object of ArrayList, adding elements into this object and storing this object into List interface. Convert elements of ArrayList into an array by using toArray().

List  interface is a member of the Java Collection Framework and extends Collection interface. It is an ordered collection which follows insertion order, typically allow duplicate elements. The class ArrayList extends AbstractList class and implements List, RandomAccess, Cloneable, Serializable interfaces. ArrayList class is a member of the Java Collections Framework.

The method used:
toArray(Object[] a): This method returns an array containing all of the elements of the given list.

The code of the program is given below:

import java.util.List;
import java.util.ArrayList;
 
public class CollectionToArray1{
    public static void main(String[] args){
        List arraylist = new ArrayList();
        arraylist.add("Java");
        arraylist.add("Struts");
        arraylist.add("J2ee");
        arraylist.add("Code");
        Object[] array = arraylist.toArray();
    System.out.println("\nThe objects into array.");
        for (int i = 0; i < array.length; i++)
        {
         System.out.println(array[i].toString());
        }
    }
}

The output of the program is given below:

C:\rajesh\kodejava>javac CollectionToArray.java
Note: CollectionToArray.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
C:\rajesh\kodejava>java CollectionToArray
The objects into array.
Java
Struts
J2ee
Code

Download this example.

                         

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

2 comments so far (
post your own) View All Comments Latest 10 Comments:

How to convert Number,String and char in vector method to array ?

Posted by varun on Saturday, 01.19.08 @ 18:14pm | #45593

how to convert a number, string and char in vector method to array

Posted by varun on Saturday, 01.19.08 @ 18:12pm | #45592

Latest Searches:
quiz
velocity rules engine
Create Scroll Bar in J
JButton with image
binary recursion
final keyword
Captcha
ajax struts
where
getting integer input
logout ajax struts2
How to write JSP
format a number decima
java jtable
java drop down list
icon a JButton
EJB 2.0 tutorials
Qt Jambi
count the number of di
J2ME Code Camp
session scope-manually
JSTL API
commons validator
program in java to ins
?ยà¸????ยà¸???ยà
MULTIPLE SELECT COMBO
check character
Photoshop Photo Effect
javascript separate in
jfreechart
Tutorial:FlashBasicPas
adding details in a js
how to retrieve values
action:scope=
how to print arraylist
how to use maps in jav
validating username an
selecting option value
bean :write excel she
Date Examples veloci
how to create a text f
jcombobox in java
velocity control ru
ant build tool
how to write hql in da
Linux Caixa Mé???é????
Write a program to acc
session jsp
chicken
set colours Jtree
retrive data from data
Aதà¯??தàÂ
jdbctemplate.execute
disable minimize butto
example of JFileChoos
HTML tags in JSP
core java Applets
post data from a servl
ั?à¹???ะà¸?ะà¸?à
set value to httpsessi
JMF
session getting time
Excel open java applic
application context in
decimals
Combattons la programm
save file name
java date compare exam
ejp
How to insert multiple
add two numbers in jav
breakаÐ?????аÐ????а
Combattons la programm
jsp bank examples
java.util.Calendar
Combattons la programm
struts1.2 html:select
getchars
json
axis 2
Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.