Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Short answer</strong>: No, you have to code it.</p> <p><strong>Long answer</strong>: List and Set both have a method for obtaining an <a href="http://download.oracle.com/javase/1.5.0/docs/api/java/util/Iterator.html" rel="nofollow">Iterator</a> (there are a few other collection classes, but probably not what your looking for). The List and Set interfaces are a part of the <a href="http://download.oracle.com/javase/1.5.0/docs/guide/collections/index.html" rel="nofollow">Collections Framework</a> which only allow for adding/removing/iterating Objects like Character or Integer (not primitives like char or int). There is a feature in <a href="http://java.sun.com/developer/technicalArticles/releases/j2se15/" rel="nofollow">Java 1.5 called auto-boxing</a> that will hide this primitive to Object conversion but I don't recommend it and it won't provide what you want in this case.</p> <p>An alternative would be to wrap the String in a class of your own that </p> <pre><code>implements Iterator&lt;Character&gt; </code></pre> <p>but that might be more work than it is worth.</p> <p>Here is a code snippet for doing what you want:</p> <pre><code>String s = ""; List&lt;Character&gt; list = new ArrayList&lt;Character&gt;(s.length()); for (int i = 0; i &lt; s.length(); i++) { // note that Character.valueOf() is preferred to new Character() // you can omit the Character.valueOf() method // and Java 1.5+ will auto-box the primitive into an Object list.add(Character.valueOf(s.charAt(i))); } Iterator&lt;Character&gt; iterator = list.iterator(); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload