Skip to content

Instantly share code, notes, and snippets.

@t81lal
Last active August 29, 2015 14:18
Show Gist options
  • Save t81lal/a7c89b00c619ca71da1e to your computer and use it in GitHub Desktop.
Save t81lal/a7c89b00c619ca71da1e to your computer and use it in GitHub Desktop.
getPackages
public static String[] getPackages(String name) {
int len = packageLength(name);
if (len == 0)
return new String[] {};
String[] arr = new String[len];
int k = 0;
char[] chars = name.toCharArray();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < chars.length; i++) {
char c = chars[i];
if (c == '/') {
arr[k++] = sb.toString();
sb.setLength(0);
if (k >= len)
break;// done, small optimisation
} else {
sb.append(c);
}
}
return arr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment