java.util.ArrayList.toArray()の使い方

Javaコード
package com.arkgame.itstudy;

import java.util.ArrayList;

public class ToArrayDemo {

public static void main(String[] args) {
ArrayList<Integer> lstAA = new ArrayList<Integer>();

lstAA.add(22);
lstAA.add(33);
lstAA.add(44);
lstAA.add(55);

System.out.println(“lstAAの要素下記:");

for (Integer number : lstAA) {
System.out.println(“Number = " + number);
}

Integer lstBB[] = new Integer[lstAA.size()];
lstBB = lstAA.toArray(lstBB);

System.out.println(“lstBBの要素下記:");
for (Integer number : lstBB) {
System.out.println(“Number = " + number);
}
}
}

結果
lstAAの要素下記:
Number = 22
Number = 33
Number = 44
Number = 55
lstBBの要素下記:
Number = 22
Number = 33
Number = 44
Number = 55

Java

Posted by arkgame