Java Scanner Usage getStrings(Properties props, String key, String sep)

Here you can find the source of getStrings(Properties props, String key, String sep)

Description

Gets an array of string properties given a key and a proper word separator.

License

Apache License

Parameter

Parameter Description
props The properties
key The key
sep The words separator

Return

An array of string properties

Declaration

public static String[] getStrings(Properties props, String key, String sep) 

Method Source Code

//package com.java2s;
/*/*from  ww w  . ja v a2s  .  co  m*/
 * Copyright 2012 Fabio Strozzi
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.ArrayList;
import java.util.Properties;
import java.util.Scanner;

public class Main {
    /**
     * Gets an array of string properties given a key and a proper word separator.
     * 
     * @param props
     *            The properties
     * @param key
     *            The key
     * @param sep
     *            The words separator
     * @return An array of string properties
     */
    public static String[] getStrings(Properties props, String key, String sep) {
        String val = props.getProperty(key);
        if (val == null || val.trim().equals(""))
            return new String[0];

        ArrayList<String> l = new ArrayList<String>(5);
        Scanner s = new Scanner(val);
        s.useDelimiter(sep);
        while (s.hasNext()) {
            String v = s.next();
            if (v != null && !v.trim().equals(""))
                l.add(v.trim());
        }
        return l.toArray(new String[0]);
    }
}

Related

  1. getNumberOfUsernames(String usernames)
  2. getOutputFromValgrindOutput(String valgrindOutput)
  3. getPartOfString(String string, int index, String delimiter)
  4. getReplay(String prompt)
  5. getScannerContents(final Scanner scanner)
  6. getStrings(Scanner sc, int n)
  7. getTimeAsInt(String duration)
  8. getTypedValue(String question)
  9. input(String message)