Splits the given string into its constituent non-empty trimmed elements, which are delimited by any of the given delimiter characters. This is a more direct and efficient implementation than using a regex (e.g. String.split()), trimming the elements and removing empty ones. @param str the string to
(String str, String delimiters, int limit)
| 2529 | * @return the non-empty elements in the string, or an empty array |
| 2530 | */ |
| 2531 | public static String[] split(String str, String delimiters, int limit) { |
| 2532 | if (str == null) |
| 2533 | return new String[0]; |
| 2534 | Collection<String> elements = new ArrayList<String>(); |
| 2535 | int len = str.length(); |
| 2536 | int start = 0; |
| 2537 | int end; |
| 2538 | while (start < len) { |
| 2539 | for (end = --limit == 0 ? len : start; |
| 2540 | end < len && delimiters.indexOf(str.charAt(end)) < 0; end++); |
| 2541 | String element = str.substring(start, end).trim(); |
| 2542 | if (element.length() > 0) |
| 2543 | elements.add(element); |
| 2544 | start = end + 1; |
| 2545 | } |
| 2546 | return elements.toArray(new String[elements.size()]); |
| 2547 | } |
| 2548 | |
| 2549 | /** |
| 2550 | * Returns a string constructed by joining the string representations of the |
no test coverage detected