<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java_Tutorial%2FCollections%2FIterable_Interface</id>
		<title>Java Tutorial/Collections/Iterable Interface - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java_Tutorial%2FCollections%2FIterable_Interface"/>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java_Tutorial/Collections/Iterable_Interface&amp;action=history"/>
		<updated>2026-04-10T18:59:24Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://jexp.ru/index.php?title=Java_Tutorial/Collections/Iterable_Interface&amp;diff=4752&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java_Tutorial/Collections/Iterable_Interface&amp;diff=4752&amp;oldid=prev"/>
				<updated>2010-06-01T05:05:37Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 05:05, 1 июня 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	<entry>
		<id>http://jexp.ru/index.php?title=Java_Tutorial/Collections/Iterable_Interface&amp;diff=4751&amp;oldid=prev</id>
		<title> в 17:44, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java_Tutorial/Collections/Iterable_Interface&amp;diff=4751&amp;oldid=prev"/>
				<updated>2010-05-31T17:44:27Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==  Creating Iterable Objects: using a for-each for loop on an Iterable object ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.util.Iterator;&lt;br /&gt;
import java.util.NoSuchElementException;&lt;br /&gt;
// This class supports iteration of the &lt;br /&gt;
// characters that comprise a string.&lt;br /&gt;
class IterableString implements Iterable&amp;lt;Character&amp;gt;, Iterator&amp;lt;Character&amp;gt; {&lt;br /&gt;
  private String str;&lt;br /&gt;
  private int count = 0;&lt;br /&gt;
  public IterableString(String s) {&lt;br /&gt;
    str = s;&lt;br /&gt;
  }&lt;br /&gt;
  // The next three methods implement Iterator.&lt;br /&gt;
  public boolean hasNext() {&lt;br /&gt;
    if (count &amp;lt; str.length()){&lt;br /&gt;
      return true;&lt;br /&gt;
    }  &lt;br /&gt;
    return false;&lt;br /&gt;
  }&lt;br /&gt;
  public Character next() {&lt;br /&gt;
    if (count == str.length())&lt;br /&gt;
      throw new NoSuchElementException();&lt;br /&gt;
    count++;&lt;br /&gt;
    return str.charAt(count - 1);&lt;br /&gt;
  }&lt;br /&gt;
  public void remove() {&lt;br /&gt;
    throw new UnsupportedOperationException();&lt;br /&gt;
  }&lt;br /&gt;
  // This method implements Iterable.&lt;br /&gt;
  public Iterator&amp;lt;Character&amp;gt; iterator() {&lt;br /&gt;
    return this;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void main(String args[]) {&lt;br /&gt;
    IterableString x = new IterableString(&amp;quot;This is a test.&amp;quot;);&lt;br /&gt;
    for (char ch : x){&lt;br /&gt;
      System.out.println(ch);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;T&lt;br /&gt;
h&lt;br /&gt;
i&lt;br /&gt;
s&lt;br /&gt;
 &lt;br /&gt;
i&lt;br /&gt;
s&lt;br /&gt;
 &lt;br /&gt;
a&lt;br /&gt;
 &lt;br /&gt;
t&lt;br /&gt;
e&lt;br /&gt;
s&lt;br /&gt;
t&lt;br /&gt;
.&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  &amp;quot;for&amp;quot; statement for Iterable object in JDK 5 has been enhanced. ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;It can iterate over a Collection without the need to call the iterator method. The syntax is&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
for (Type identifier : expression) {&lt;br /&gt;
         statement (s)&lt;br /&gt;
     }&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;A&lt;br /&gt;
B&lt;br /&gt;
C&lt;br /&gt;
D&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Iterable interface: while loop and for loop ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.util.Arrays;&lt;br /&gt;
import java.util.Iterator;&lt;br /&gt;
import java.util.List;&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    List list = Arrays.asList(&amp;quot;A&amp;quot;, &amp;quot;B&amp;quot;, &amp;quot;C&amp;quot;, &amp;quot;D&amp;quot;);&lt;br /&gt;
     Iterator iterator = list.iterator();&lt;br /&gt;
     while (iterator.hasNext () ) {&lt;br /&gt;
         String element = (String) iterator.next ();&lt;br /&gt;
         System.out.println(element);&lt;br /&gt;
     }&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;A&lt;br /&gt;
B&lt;br /&gt;
C&lt;br /&gt;
D&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Using an Iterator ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;The Iterator interface has the following methods:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;OL&amp;gt;&amp;lt;LI&amp;gt;hasNext.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;next.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;remove.&amp;lt;/LI&amp;gt;&amp;lt;/OL&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Compared to an Enumeration, hasNext() is equivalent to hasMoreElements() and next() equates to nextElement().&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.util.ArrayList;&lt;br /&gt;
import java.util.Collection;&lt;br /&gt;
import java.util.Iterator;&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void main(String[] a) {&lt;br /&gt;
    Collection c = new ArrayList();&lt;br /&gt;
    c.add(&amp;quot;1&amp;quot;);&lt;br /&gt;
    c.add(&amp;quot;2&amp;quot;);&lt;br /&gt;
    c.add(&amp;quot;3&amp;quot;);&lt;br /&gt;
    Iterator i = c.iterator();&lt;br /&gt;
    while (i.hasNext()) {&lt;br /&gt;
      System.out.println(i.next());&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;1&lt;br /&gt;
2&lt;br /&gt;
3&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
			</entry>

	</feed>