replace the String[] with an arrayList (servList)

This commit is contained in:
js 2020-03-03 08:48:21 +01:00 committed by Louis
parent 1ec120c373
commit c981309ef6

View File

@ -1,6 +1,11 @@
package tools;
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.ListIterator;
public class HostList{
/** Helper to get the server list from the user
@ -10,18 +15,21 @@ public class HostList{
* @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);
String servName = "";
int i = 0;
do {
System.out.println("Name of the next server:");
servName = scanner.nextLine();
if (servName != "stop"){
serverList[i] = servName;
serverList.add(servName);
}
++i;
} while (servName != "stop");
return serverList;
}