replace the String[] with an arrayList (servList)

pull/23/head
js 5 years ago committed by Louis
parent 424af59780
commit 78deb16e41

@ -1,6 +1,11 @@
package tools; package tools;
import java.util.Scanner; import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.ListIterator;
public class HostList{ public class HostList{
/** Helper to get the server list from the user /** Helper to get the server list from the user
@ -10,18 +15,21 @@ public class HostList{
* @version 1.0 * @version 1.0
*/ */
public String[] getServList(){ /**
String[] serverList = new String[20]; * Let the user enter all server and puts it in a list
* @return list of servers
*/
public List<String> getServList(){
List<String> serverList = new ArrayList<String>();
Scanner scanner = new Scanner(System.in); Scanner scanner = new Scanner(System.in);
String servName = ""; String servName = "";
int i = 0;
do { do {
System.out.println("Name of the next server:"); System.out.println("Name of the next server:");
servName = scanner.nextLine(); servName = scanner.nextLine();
if (servName != "stop"){ if (servName != "stop"){
serverList[i] = servName; serverList.add(servName);
} }
++i;
} while (servName != "stop"); } while (servName != "stop");
return serverList; return serverList;
} }

Loading…
Cancel
Save