Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Array List Java [closed] without wasting too much if your time.
The question is published on by Tutorial Guruji team.
The question is published on by Tutorial Guruji team.
Please can somebody help me? I’m learning about Array List in Java, I found interesting things in this lesson (Stanford CS106a)
https://www.youtube.com/watch?v=YJ9FlCFi3c8&feature=youtu.be&list=PL84A56BC7F4A1F852&t=1385
But when I tried to run this program in Eclipse it gives me many errors 🙁
What’s wrong with this? (Why is void invalid type for the variable printList?)
import java.util.ArrayList; import acm.program.*; class ArrayListEx extends ConsoleProgram { public void run () { ArrayList<String> sList = new ArrayList <String>(); readList (sList); printList (sList); readList (sList); printList (sList); private void readList (ArrayList list) { while (true) { String line = readLine("Unesi tekst"); if (line.equals("")) break; list.add(line); } } private void printList (ArrayList lista) { println ("List contains: " + lista.size() + " elements."); for (int i = 0; i< lista.size(); i++) { println(lista.get(i)); } } } }
Answer
The issue was no } bracket on your run function and an extra } at the end of your printList function. Also have changed run() to init(). This should hopefully work for you.
import java.util.ArrayList; import acm.program.*; public class ArrayListEx extends ConsoleProgram { public void init () { ArrayList<String> sList = new ArrayList <String>(); readList (sList); printList (sList); readList (sList); printList (sList); } private void readList (ArrayList list) { while (true) { String line = readLine("Unesi tekst"); if (line.equals("")) break; list.add(line); } } private void printList (ArrayList lista) { println ("List contains: " + lista.size() + " elements."); for (int i = 0; i< lista.size(); i++) { println(lista.get(i)); } } }
We are here to answer your question about Array List Java [closed] - If you find the proper solution, please don't forgot to share this with your team members.