Kamis, 23 Januari 2014

Contoh Java Collection Set

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.brainmatics.java.fundamental.collection;

import java.util.Set;
import java.util.TreeSet;
import javax.swing.JOptionPane;

/**
 *
 * @author Student 5
 */
public class SetExample {
   
    public static void main(String[] args) {
       
        Set<String> mahasiswaSet = new TreeSet<String>();
       
        for(int i=0;i<5;i++){
            String mahasiswa =
                    JOptionPane.showInputDialog("Masukkan nama mahasiswa, harus unik!");
            mahasiswaSet.add(mahasiswa);
        }
       
        for (String mhs : mahasiswaSet) {
            System.out.println("Nama : " + mhs);
        }
       
    }
}

Tidak ada komentar:

Posting Komentar