IT. Expert System.

Java basics

toArray()


This method returns an array containing all of the elements in this list in proper sequence (from first to last element).

Syntax:
Library: java.util.ArrayList

public  T[] toArray(T[] a)


Example:

import java.util.ArrayList;

public class ArrayListDemo {
   public static void main(String[] args) {
      
    // create an empty array list with an initial capacity
    ArrayList arrlist = new ArrayList();

    // use add() method to add values in the list
    arrlist.add(10);
    arrlist.add(12);
    arrlist.add(31);
    arrlist.add(49);
	
    System.out.println("Printing elements of array1");

    // let us print all the elements available in list
    for (Integer number : arrlist) {
      System.out.println("Number = " + number);
    }  

    // toArray copies content into other array
    Integer list2[] = new Integer[arrlist.size()];
    list2 = arrlist.toArray(list2);

    System.out.println("Printing elements of array2");

    // let us print all the elements available in list
    for (Integer number : list2) {
      System.out.println("Number = " + number);
    }
  }
} 
Output:

Printing elements of array1
Number = 10
Number = 12
Number = 31
Number = 49
Printing elements of array2
Number = 10
Number = 12
Number = 31
Number = 49


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 584 / . Delta: 0.06391 с