replace the String[] with an arrayList (servList)

pull/30/head
js 5 years ago committed by Louis
parent 1ec120c373
commit c981309ef6

@ -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;
}

Loading…
Cancel
Save