Here you can find the source of splitArrayElementsIntoProperties(String[] array, String delimiter)
Parameter | Description |
---|---|
array | a parameter |
delimiter | a parameter |
public static Properties splitArrayElementsIntoProperties(String[] array, String delimiter)
//package com.java2s; import java.util.*; public class Main { /**/*from ww w .jav a 2 s. co m*/ * * @param array * @param delimiter * @return Properties */ public static Properties splitArrayElementsIntoProperties(String[] array, String delimiter) { return splitArrayElementsIntoProperties(array, delimiter, null); } /** * * @param array * @param delimiter * @param charsToDelete * @return Properties */ public static Properties splitArrayElementsIntoProperties(String[] array, String delimiter, String charsToDelete) { if (array == null || array.length == 0) { return null; } Properties result = new Properties(); for (int i = 0; i < array.length; i++) { String element = array[i]; if (charsToDelete != null) { element = deleteAny(array[i], charsToDelete); } String[] splittedElement = split(element, delimiter); if (splittedElement == null) { continue; } result.setProperty(splittedElement[0].trim(), splittedElement[1].trim()); } return result; } /** * * @param inString * @param charsToDelete * @return String */ public static String deleteAny(String inString, String charsToDelete) { if (inString == null || charsToDelete == null) { return inString; } StringBuffer out = new StringBuffer(); for (int i = 0; i < inString.length(); i++) { char c = inString.charAt(i); if (charsToDelete.indexOf(c) == -1) { out.append(c); } } return out.toString(); } public static String[] split(String splittee, String splitChar) { return split(splittee, splitChar, 0); } /** * String split method * @param splittee input string * @param splitChar split text * @param limit split limit number * @return String[] */ public static String[] split(String splittee, String splitChar, int limit) { String taRetVal[]; StringTokenizer toTokenizer; int tnTokenCnt; try { toTokenizer = new StringTokenizer(splittee, splitChar); tnTokenCnt = toTokenizer.countTokens(); if (limit != 0 && tnTokenCnt > limit) tnTokenCnt = limit; taRetVal = new String[tnTokenCnt]; for (int i = 0; i < tnTokenCnt; i++) { if (toTokenizer.hasMoreTokens()) { taRetVal[i] = toTokenizer.nextToken(); } if (limit != 0 && limit == (i + 1)) break; } } catch (Exception e) { taRetVal = new String[0]; } return taRetVal; } }