久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

迭代器上的 next() 方法如何工作?

How does next() method on iterators work?(迭代器上的 next() 方法如何工作?)
本文介紹了迭代器上的 next() 方法如何工作?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我對迭代器上的 next() 方法有疑問.如果我將這行代碼作為我的代碼的一部分(使用 arrayOfStrings size = 4):

I have a doubt with the next() method on iterators. If I have as a part of my code this lines (with arrayOfStrings size = 4):

Iterator<String> it = arrayOfStrings.iterator(); //arrayOfString is ArrayList<String>

while(it.hasNext()) {
    String e = it.next();
    System.out.println(e);
}

在第一次迭代時,迭代器開始指向索引為 0 的元素?還是像索引-1"?

At the very first iteration, the iterator starts pointing to element with index 0? or like the "index -1" ?

我問是因為據我所知 next() 方法返回集合中的下一個元素.

I ask because as far as I know the next() method returns the next element in the collection.

所以,如果在第一次迭代中,當調用 next() 時迭代器從索引 0 開始,它會返回索引 1 處的元素,我將無法對索引為 0 的元素?

So, if at the very first iteration the iterator starts at index 0 when next() is invoked, it returns the element at index 1 and I won′t be able to do nothing with the element at index 0?

推薦答案

next 視為一個兩步過程.首先它獲取迭代器中的下一項,然后遞增指針以指向下一項.因此,當您創建一個新的迭代器時,它會被初始化為返回列表中的第一項(索引 0).

Think of next as a two-step process. First it gets the next item in the iterator, then it increments the pointer to point to the next item. So, when you create a new iterator, it is initialized to return the first item (index 0) in your list.

這篇關于迭代器上的 next() 方法如何工作?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Java Remove Duplicates from an Array?(Java從數組中刪除重復項?)
egit plugin for Eclipse(Eclipse 的 egit 插件)
Gitlab cannot open git-upload-pack error(Gitlab 無法打開 git-upload-pack 錯誤)
How to fix Invocation failed Unexpected Response from Server: Unauthorized in Android studio(如何修復調用失敗來自服務器的意外響應:在 Android 工作室中未經授權)
How to add GitLab repository in Eclipse?(如何在 Eclipse 中添加 GitLab 存儲庫?)
AES encryption, got extra trash characters in decrypted file(AES 加密,解密文件中有多余的垃圾字符)
主站蜘蛛池模板: 国产一级18片视频 | 日韩aaaa| 国产精品剧情 | 日韩免费一区二区 | 久久怡红院 | 亚洲精品一二三区 | 免费性网站 | 午夜黄视频 | 中国黄色1级片 | 免费在线 | 美日韩在线 | 在线观看视频一区二区 | 国产福利视频在线 | 黄色免费片 | 9l视频自拍九色9l视频成人 | 狠狠干网 | 国产一级网站 | 国产一区二区三区在线 | 亚洲精品1| 黄色小视频在线观看 | 国产精品一品二区三区的使用体验 | 日本免费不卡视频 | 国产又粗又猛又黄又爽的视频 | www.日日夜夜 | 国内自拍偷拍 | 免费黄色小视频 | 伊人国产女| 日韩女优在线 | 国产午夜影院 | 久久98| 97视频免费在线观看 | 成年人小视频 | 好色影院| 久久久久久免费 | 久久高清免费视频 | 日本www色 | 日韩精品一级 | 欧美日韩成人一区二区三区 | 久久成人精品 | 国产精品美女在线 | 国产三级做爰高清在线 |