Java tutorial
//package com.java2s; import java.util.ArrayList; import java.util.List; public class Main { public static String[] filterRoom(List<String> longRoomList, String buildingNumber, String floorNumber, String prefix) { if (longRoomList == null) { return null; } List<String> room_info = new ArrayList<String>(); for (int i = 0; i < longRoomList.size(); ++i) { String[] slice = longRoomList.get(i).split("-"); if (slice.length == 4 && slice[0].equals(buildingNumber) && slice[1].equals(floorNumber) && !room_info.contains(prefix + slice[2])) { room_info.add(prefix + slice[2]); } } return listToArray(room_info); } public static String[] listToArray(List<String> l) { String[] a = new String[l.size()]; for (int i = 0; i < l.size(); i++) { a[i] = l.get(i); } return a; } }