Total members 11895 |It is currently Wed Dec 18, 2024 3:18 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Convert array to a list object using asList function
Code:

import java
.util.Arrays;
import java.util.List;

public class ArraysWork {

    public static void main(String[] args) {
         
        
// Strings array
        String cityStrings[] = {"NewYork", "Toronto", "Delhi", "Cairo"};
        // Integers array
        Integer numbers[] = {4, 3, 11};

        // List references
        List listStrings = null;
        List listIntegers = null;

        // Convert strings array to list object
        listStrings = Arrays.asList(cityStrings);
       
        System
.out.println("Size of the strings list: "+listStrings.size());
        System.out.println("Value at index 1->"+ listStrings.get(1));
        System.out.println("Calling toString function :"+listStrings);

        // Convert numbers array to list object
         listIntegers = Arrays.asList(numbers);
        System.out.println("Size of the numbers list: " + listIntegers.size());
        System.out.println("Value at index 1->"+listIntegers.get(1));
        System.out.println("Calling toString function :"+ listIntegers);

    }
}
 


The output is :

Code:
Size of the strings list: 4
Value at index 1->Toronto
Calling toString function :[NewYork, Toronto, Delhi, Cairo]
Size of the numbers list: 3
Value at index 1->3
Calling toString function :[4, 3, 11]




_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Convert normal array to a list
 Convert TreeSet content to array     -  
 Removing elements from array list with the iterator     -  
 Normal Distrubtion     -  
 Array difference for associate array     -  
 compare an array with another array?     -  
 How to Convert WMV to AVI on Mac     -  
 convert pascal code to c ?     -  
 convert hexadecimal to decimal     -  
 Convert outputstream to inputstream     -  



cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com