List'in Array'e donusmesi

java
  • Turgay Can
  • Tarih

    02 Feb, 2014
  • Yorum

    0
  • Görüntüleme

    1672
  • İndirme

    0

List'in Array'e donusmesi

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author turgay
 */
public class NewMain {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        List customerList = new ArrayList();
        customerList.add(new Customer(1, "Turgay", "Can"));
        customerList.add(new Customer(2, "Enes", "Kantepe"));
        customerList.add(new Customer(3, "Utku", "Sönmez"));
        customerList.add(new Customer(4, "Maksut", "Spahi"));
        customerList.add(new Customer(5, "Batuhan", "Bayrakçı"));

        Customer[] customerArray = customerList.toArray(new Customer[customerList.size()]);

        for (Customer customer : customerArray) {
            System.out.println("ID : " + customer.getId());
        }
    }

    static class Customer {

        private int id;
        private String name;
        private String surname;

        public Customer(int id, String name, String surname) {
            this.id = id;
            this.name = name;
            this.surname = surname;
        }

        public int getId() {
            return id;
        }

        public void setId(int id) {
            this.id = id;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getSurname() {
            return surname;
        }

        public void setSurname(String surname) {
            this.surname = surname;
        }

    }

}

Çıktı :

ID : 1
ID : 2
ID : 3
ID : 4
ID : 5
BUILD SUCCESSFUL (total time: 0 seconds)

0 Yorum..

Yorum yapmak için "Giriş yapın" yada "Misafir üye" olarak yorum yapabilirsiniz.

Yorum Yap