Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Array to Collection 
 

In this example we are converting values of an array into collection.

 

Array to Collection

                         

In this example we are converting values of an array into collection.

List  interface is a member of the Java Collection Framework and extends Collection interface. List interface is an ordered collection which follows insertion order, typically allow duplicate elements. The List interface provides a special iterator, called ListIterator for insertion, replacement and  bi-directional access. 
The Arrays class contains various methods for manipulating arrays (e.g. sorting and searching etc.) and extends the Object class. The Iterator class allows access to the elements of a collection.

Methods used:
hasNext():
This method is used to get more elements. If the element at the next position is found then returns true otherwise throws an exception.

next(): This method returns the next element in the iteration.

asList(Object[] a): This method acts as a bridge between array and collection. This method converts array into Arrays by internally using  Colletion.toArray() method .

The code of the program is given below:

import java.util.Arrays;
import java.util.List;
import java.util.Iterator;
 
public class ArraysToCollection{
    public static void main(String[] args){
    String[] array = {"Java""Struts""JSP""J2EE"};
    List list = Arrays.asList(array);
    Iterator iterator = list.iterator();
    System.out.println("\nThe values into Array");
    while (iterator.hasNext()){
     System.out.println((Stringiterator.next());
     }
   }
}

The output of the program is given below:

C:\rajesh\kodejava>javac ArraysToCollection.java
C:\rajesh\kodejava>java ArraysToCollection
The values into Array
Java
Struts
JSP
J2EE

Download this example.

                         

» View all related tutorials
Related Tags: c file array class list ui lists method get name using this oo root example where to exam drive store

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

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

how to return a list?

Posted by harsha on Monday, 12.17.07 @ 19:02pm | #42727

Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

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 | Flex 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.