+ 1
What is the error in this code and how to correct it?
How to solve this error. check my codes for code. import java.util.*; public class Program { public static void main(String[] args) { ArrayList<String> a=new ArrayList<String>(); a.add("hdjdj"); a.add("eudu"); a.add("ejxj"); Iterator it=a.iterator(); while(it.hasNext()) { System .out.print(it.Next()+""); } } }
9 Answers
+ 2
Your code has one error calling iterator method "next()" inside while loop... In next() method all the characters should be in lower case..
- One more improvement should be provide some spacing after printing list elements.. you have just appended empty string it should be space..
I have modified ur code please refere and execute it..
-----------------------------------------
import java.util.*;
public class Program
{
public static void main(String[] args) {
ArrayList<String> a=new ArrayList<String>();
a.add("hdjdj");
a.add("eudu");
a.add("ejxj");
Iterator it=a.iterator();
while(it.hasNext())
{
System .out.print(it.next()+" ");
}
}
}
-----------------------------------------
Hope it helps,
Happy Programming ;)
+ 7
Inside the while loop,
System.out.println(it.next()+""); is correct.
+ 1
thanks sir@krishna got it nowđ
+ 1
Thank you đ@sbk
I was about to ask the difference between Next() and next().and thanks for the adviceđ
+ 1
@Manideep, In Iterator interface there is no such method named Next(). so there is no difference between the two.. Ideally every method provided by java API starts with lower case.. Only class names and interface names starts with upper case..
Thanks :)
+ 1
java API? Interface ??no idea! still have a long way to gođ
.Thanks again@sbk
+ 1
No kidding đ
@sbk.
I am only still half way through java course in sololearn, and still there's a lot more to learn form outsideđ.
0
@Manideep I guess u r kidding
0
Haha ok then.. Good luck đđ