开发者

How can I index the arraylist by a long?

开发者 https://www.devze.com 2023-02-24 10:12 出处:网络
I have filled an arraylist<string> with 20 lacs strings. If I want to iterate like this, for(long i=0;arrlist.size();i++{

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

精彩评论

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