我有两种方法可以读取字符串,并创建Character对象:
static void newChar(String string) {
int len = string.length();
System.out.println("Reading " + len + " characters");
for (int i = 0; i < len; i++) {
Character cur = new Character(string.charAt(i));
}
}
Run Code Online (Sandbox Code Playgroud)
和
static void justChar(String string) {
int len = string.length();
for (int i = 0; i < len; i++) {
Character cur = string.charAt(i);
}
}
Run Code Online (Sandbox Code Playgroud)
当我使用18,554,760字符串运行方法时,我的运行时间差异很大.我得到的输出是:
newChar took: 20 ms
justChar took: 41 ms
Run Code Online (Sandbox Code Playgroud)
对于较小的输入(4,638,690个字符),时间不会变化.
newChar took: 12 ms
justChar took: 13 ms
Run Code Online (Sandbox Code Playgroud)
在这种情况下,为什么新的效率更高?
编辑: …
我正在尝试通过Parse Mealspotting教程,但在添加Parse库后,我得到了奇怪的错误.我在google搜索时发现了其他类似的错误,但没有任何效果.这是一个.我也看了看添加支持库,但是没有解决它.
确切的文字是:
Multiple markers at this line
- The type bolts.Task cannot be resolved. It is indirectly referenced from required .class files
- The class file Task<?> contains a signature 'Ljava/util/Set<Lbolts/Task<*>.TaskCompletionSource;>;' ill-formed at
position 30
我不关心支持库或应用程序将使用哪些设备,我想要的就是这个,所以我可以通过本教程.以前有人处理过这个吗?
我也尝试过创建一个只支持Kit Kat并删除了支持库的项目,但它仍然会抛出相同的错误.