Home Java Java-conversion Convert Array to List



Convert Array to List
Posted on: August 6, 2007 at 12:00 AM
In this section, you will learn to convert an Array to List.

Convert Array to List

     

In this section, you will learn to convert an Array to List. 

Code Description:

This program helps you in converting an Array to List. Here we have taken an array of data which gets converted to List using Array.asList mathod. We have also used collection.sort method to get the data in sorted order.

import java.util.Arrays;
import java.util.Collections;
import java.util.*;
import java.io.*;

public class ArrToList {
  public static void main(String args[]) {
  String[] strArray = new String[] {"Piano""Guitar",
 
"Flute""Drums","Violen"};

  List l = Arrays.asList(strArray);
  Collections.sort(l);
  System.out.println(l);
  }
}

Output of the program: 

C:\unique>javac ArrToList.java

C:\unique>java ArrToList
[Drums, Flute, Guitar, Piano, Violen]

C:\unique>

Download this example.

 

Related Tags for Convert Array to List:
cmatharraylistdataconverthelpgetusingthisprogramtoramerteliinconvertingasmpsprowhichsatkisharaygetsarrtslissthavstpronogro


More Tutorials from this section

Ask Questions?    Discuss: Convert Array to List   View All Comments

Post your Comment


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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.