Skip to content

Instantly share code, notes, and snippets.

@gabrielfern
Created June 22, 2017 03:23
Show Gist options
  • Save gabrielfern/7c9825cc68a9559eaa7c9e2769565eb9 to your computer and use it in GitHub Desktop.
Save gabrielfern/7c9825cc68a9559eaa7c9e2769565eb9 to your computer and use it in GitHub Desktop.
my toArray
@SuppressWarnings("unchecked")
@Override
public T[] toArray() {
T[] result = null;
if (!this.isEmpty()) {
result = (T[]) new Object[1];
result[0] = this.data;
result = this.juntaArrays(result, this.next.toArray());
}
if (result == null) {
result = (T[]) new Object[0];
}
return result;
}
public T[] juntaArrays(T[] first, T[] second) {
T[] result = Arrays.copyOf(first, first.length + second.length);
System.arraycopy(second, 0, result, first.length, second.length);
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment