Last active
August 29, 2015 14:18
-
-
Save t81lal/a7c89b00c619ca71da1e to your computer and use it in GitHub Desktop.
getPackages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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