开发者

How can I index the arraylist by a long?

I have filled an arraylist<string> with 20 lacs strings. If I want to iterate like this,

for(long i=0;arrlist.size();i++{
   arrlist.get(i);  

}

But, arrlist.get() doesn't support index as long. Moreover, I cannot use iterator, so, how do I iterate without a开发者_StackOverflow社区n Iterator? Pleas don't ask why I'm not using iterator.


From your question it seems you are trying to iterate over each element. Note that for this purpose you may use the nicer for loop:

for(String element: arrlist) {
   // Do whatever you want with your element
}  


I think arrlist.get((int) i) should work. Or you could just declare i as int.


ArrayList#size() doesn't return long but int. No need to use a long variable inside the for loop.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜