From 78deb16e41cb1f4c2282a6e4e77ae45a96f82f3d Mon Sep 17 00:00:00 2001 From: js Date: Tue, 3 Mar 2020 08:48:21 +0100 Subject: [PATCH] replace the String[] with an arrayList (servList) --- src/tools/HostList.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/tools/HostList.java b/src/tools/HostList.java index 0d8ea59..4acaf92 100644 --- a/src/tools/HostList.java +++ b/src/tools/HostList.java @@ -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 getServList(){ + List serverList = new ArrayList(); 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; }