Can anyone tell me what's wrong in the lower part of the code?
public static zero main (string [] args) {list & lt; String & gt; L = New Arrestist & lt; String & gt; (); L.add ("1"); L.add ("2"); L.add ("3"); L.add ("4"); For (int i = 0; i & lt; l.size (); i ++) {if (l.get (i) similarities ("1") l.remove (l.get (i)); Else System.out.println (l.get (i));}} gives me a product of [3.4] instead of [2,3,4]. Wheres my [2]? The reason for this is: Paco "3", giving an output of "4" An alternative implementation can be:
When I = 0 you first element And I get 1 - when I = 1 is on the third element, because you have written everything down to 1, you write "3" - when I = 2 you get the third element Writes "which is" 4 "
import java.util.ArrayList; Import java.util.Iterator ; Import java.util.List; public square item {public static zero main (string [] args) {list & lt; string & gt; l = new arrelist & lt; string & gt; (); l.add (" 1 "); l.add (" 2 "); l.add (" 3 "); l.add (" 4 "); Iterator & lt; string> IARAR = L. knitter; .hasNext ()) {string value = iter.next (); If ("1" .equals (value)) {iter.remove (); } Else {System.out.println (value); }}}}
Comments
Post a Comment