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

Java中的Iterator接口有什么好處?

What are the benefits of the Iterator interface in Java?(Java中的Iterator接口有什么好處?)
本文介紹了Java中的Iterator接口有什么好處?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我剛剛了解了 Java 集合框架如何在鏈表中實現數據結構.據我了解, Iterators 是一種遍歷數據結構(如列表)中的項目的方法.為什么要使用這個接口?為什么 hasNext()next()remove() 方法不直接編碼到數據結構實現本身?

I just learned about how the Java Collections Framework implements data structures in linked lists. From what I understand, Iterators are a way of traversing through the items in a data structure such as a list. Why is this interface used? Why are the methods hasNext(), next() and remove() not directly coded to the data structure implementation itself?

來自 Java 網站:鏈接文本

From the Java website: link text

公共接口迭代器

An集合上的迭代器.迭代器代替枚舉中的Java 集合框架.迭代器在兩個方面不同于枚舉:

public interface Iterator<E>

An iterator over a collection. Iterator takes the place of Enumeration in the Java collections framework. Iterators differ from enumerations in two ways:

  • 迭代器允許調用者刪除來自底層的元素在迭代期間收集定義明確的語義.
  • 方法名稱已經改進.

    • Iterators allow the caller to remove elements from the underlying collection during the iteration with well-defined semantics.
    • Method names have been improved.

      我嘗試用谷歌搜索,但似乎找不到明確的答案.有人能解釋一下 Sun 選擇使用它們的原因嗎?是因為更好的設計嗎?提高安全性?好的 OO 實踐?

      I tried googling around and can't seem to find a definite answer. Can someone shed some light on why Sun chose to use them? Is it because of better design? Increased security? Good OO practice?

      任何幫助將不勝感激.謝謝.

      Any help will be greatly appreciated. Thanks.

      推薦答案

      為什么要用這個接口?

      Why is this interface used?

      因為它支持允許客戶端程序員迭代任何類型的集合的基本操作(注意:不一定是 Object 意義上的 Collection).

      Because it supports the basic operations that would allow a client programmer to iterate over any kind of collection (note: not necessarily a Collection in the Object sense).

      為什么方法...不是直接的編碼到數據結構實現本身?

      Why are the methods... not directly coded to the data structure implementation itself?

      他們是,他們只是被標記為私人,所以你不能接觸他們并與他們混為一談.更具體地說:

      They are, they're just marked Private so you can't reach into them and muck with them. More specifically:

      • 您可以實現 Iterator 或對其進行子類化,這樣它就可以做一些標準的不做的事情,而不必改變它所迭代的實際對象.
      • 可以遍歷的對象不需要讓它們的接口被遍歷方法弄得一團糟,尤其是任何高度專業化的方法.
      • 您可以將 Iterators 分發給任意數量的客戶端,每個客戶端都可以按照自己的速度以自己的時間遍歷.
      • 特別是 java.util 包中的
      • Java Iterators 如果支持它們的存儲在您仍然有 Iterator 輸出的情況下被修改,則會引發異常.此異常讓您知道 Iterator 現在可能正在返回無效對象.
      • You can implement or subclass an Iterator such that it does something the standard ones don't do, without having to alter the actual object it iterates over.
      • Objects that can be traversed over don't need to have their interfaces cluttered up with traversal methods, in particular any highly specialized methods.
      • You can hand out Iterators to however many clients you wish, and each client may traverse in their own time, at their own speed.
      • Java Iterators from the java.util package in particular will throw an exception if the storage that backs them is modified while you still have an Iterator out. This exception lets you know that the Iterator may now be returning invalid objects.

      對于簡單的程序,這似乎都不值得.不過,使它們有用的那種復雜性很快就會出現.

      For simple programs, none of this probably seems worthwhile. The kind of complexity that makes them useful will come up on you quickly, though.

      這篇關于Java中的Iterator接口有什么好處?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

Java Remove Duplicates from an Array?(Java從數組中刪除重復項?)
How to fix Invocation failed Unexpected Response from Server: Unauthorized in Android studio(如何修復調用失敗來自服務器的意外響應:在 Android 工作室中未經授權)
AES encryption, got extra trash characters in decrypted file(AES 加密,解密文件中有多余的垃圾字符)
AES Error: Given final block not properly padded(AES 錯誤:給定的最終塊未正確填充)
Detecting incorrect key using AES/GCM in JAVA(在 JAVA 中使用 AES/GCM 檢測不正確的密鑰)
AES-256-CBC in Java(Java 中的 AES-256-CBC)
主站蜘蛛池模板: 欧美一区二区三区四区五区无卡码 | 亚洲国产一区二区三区在线观看 | 亚洲国产精品久久久 | 日韩在线视频播放 | 成人在线一区二区三区 | 国产精品久久久久久久岛一牛影视 | 国产在线观看av | 久热中文字幕 | 黄色免费网站在线看 | 日韩欧美综合 | 欧美一级特黄aaa大片在线观看 | 一区二区三区视频播放 | 日韩专区中文字幕 | 69av在线视频 | 91在线观看免费 | 日韩中文一区二区 | 欧美亚洲视频在线观看 | 一区二区国产精品 | 99re6在线视频精品免费 | 精品中文字幕一区 | 亚洲一区二区三区观看 | 国产99久久久国产精品 | 黄色成人在线网站 | 久久r免费视频 | 国产超碰人人爽人人做人人爱 | 国产欧美一区二区三区国产幕精品 | 亚洲国产精品久久久久秋霞不卡 | 视频1区2区| 色女人天堂 | 新超碰97 | 超碰在线免费公开 | 久久99久久98精品免观看软件 | 麻豆亚洲| 欧美在线看片 | 伦理片97 | 成人国产精品久久久 | 久久成人免费观看 | 九一精品| 一区中文字幕 | 九九九视频在线 | 黄色在线观看网址 |