Java Utililty Methods Array Flatten

List of utility methods to do Array Flatten

Description

The list of methods to do Array Flatten are organized into topic(s).

Method

Object[]flattenArray(Object... objects)
flatten Array
List result = new ArrayList();
for (Object obj : objects) {
    if (obj instanceof Object[]) {
        result.addAll(Arrays.asList((Object[]) obj));
    } else if (obj instanceof List) {
        result.addAll((List) obj);
    } else {
        result.add(obj);
...
StringflattenArray(Object[] words)
Converts object array to a big string separated by comma.
return flattenArray(words, ",");
StringflattenArray(String[] aString)
Flattens a string array for printing with NO commas
StringBuilder sb = new StringBuilder();
for (String s : aString) {
    if (sb.length() > 0)
        sb.append(" ");
    sb.append(s.toString());
return sb.toString();
StringflattenBytes(byte[] b)
flatten Bytes
String out = "";
for (int i = 0; i < b.length; i++) {
    out += ", " + b[i];
return out;
intflattenIndices(int[] indices, int[] extents)
Given n-dimensional indices and their dimensional extents flatten them into a 1d index.
int totalIdx = 0;
for (int i = 0; i < indices.length; i++) {
    int idx = indices[i];
    for (int j = 0; j < i; j++) {
        int extent = extents[j];
        idx *= extent;
    totalIdx += idx;
...
StringflattenNTriples(final String[] values)
Flatten a list of triples to n-tuples containing many objects for the same subject/predicate pair.
final Map<String, StringBuilder> map = new HashMap<String, StringBuilder>();
return flattenNTriples(values, map);
StringflattenStringArray(String[] s_array, String delimiter)
flatten String Array
StringBuffer flat = new StringBuffer();
for (int i = 0; i < s_array.length; i++) {
    flat.append(s_array[i]).append(delimiter);
return flat.toString();