Exemple #1
0
 /**
  * Convert an int array to the Java source code that represents this array. Null will be converted
  * to 'null'.
  *
  * @param array the int array
  * @return the Java source code (including new int[]{})
  */
 public static String quoteJavaIntArray(int[] array) {
   if (array == null) {
     return "null";
   }
   StatementBuilder buff = new StatementBuilder("new int[]{");
   for (int a : array) {
     buff.appendExceptFirst(", ");
     buff.append(a);
   }
   return buff.append('}').toString();
 }
Exemple #2
0
 /**
  * Combine an array of strings to one array using the given separator character. A backslash and
  * the separator character and escaped using a backslash.
  *
  * @param list the string array
  * @param separatorChar the separator character
  * @return the combined string
  */
 public static String arrayCombine(String[] list, char separatorChar) {
   StatementBuilder buff = new StatementBuilder();
   for (String s : list) {
     buff.appendExceptFirst(String.valueOf(separatorChar));
     if (s == null) {
       s = "";
     }
     for (int j = 0, length = s.length(); j < length; j++) {
       char c = s.charAt(j);
       if (c == '\\' || c == separatorChar) {
         buff.append('\\');
       }
       buff.append(c);
     }
   }
   return buff.toString();
 }