Q:

JAVA-How to get all keys from an array that start with a certain string?

I am trying to get some values from config file. I have lot of keys and want to get only certain values. These values have keys starting with same initial name with a slight variation towards the end.
can Someone help me quickly?

A:

I am assuming you are scanning the config file for Strings that have similar prefixes. Why not try scanning them in grouped instead of scanning them in all in one hashmap. If you know already the specified prefixes try creating an arraylist for each prefix and while scanning receive the given prefix and add it accordingly.
StringTokenizer s = new StringTokenizer ("Configuration File : Server_intenties = keyId_11503, keyId_11903 : Server_passcodes = keyCode_1678, keyCode_9893", " ");
ArrayList<String> keyCode = new ArrayList();
ArrayList<String> keyId = new ArrayList();

while(s.hasMoreTokens){
    String key = s.nextToken

    if(key.contains("keyId")){
         keyId.add(key);
    }

    if(key.contains("keyCode")){
         keyCode.add(key);
    }
}

System.out.println(keyCode);
System.out.println(keyId);

