Here you can find the source of parseArray(String array)
Parameter | Description |
---|---|
array | The array to parse. |
public static List<String> parseArray(String array)
//package com.java2s; import java.util.ArrayList; import java.util.List; public class Main { /**/*w w w . j ava 2 s . co m*/ * Parse an SQL array. * @param array The array to parse. * @return The parsed array, as a list. */ public static List<String> parseArray(String array) { char[] input = array.substring(1, array.length() - 1) .replace("\\\\", "\\").toCharArray(); List<String> output = new ArrayList<>(); StringBuilder elem = new StringBuilder(); boolean inQuotes = false; boolean escaped = false; for (char c : input) { if (escaped) { elem.append(c); escaped = false; } else if (c == '"') { inQuotes = !inQuotes; escaped = false; } else if (c == '\\') { escaped = true; } else { if (inQuotes) { elem.append(c); } else if (c == ',') { output.add(elem.toString()); elem.setLength(0); // This is basically .clear() } else { elem.append(c); } escaped = false; } } if (elem.length() > 0) { output.add(elem.toString()); } return output; } }