How tooutprint the statements added to a list ?

Hi all

I want to out print the statements added to wordlist

but the output result the word 'null' why?

and how to outprint them?

thanks

import java.util.ArrayList;

import java.util.LinkedList;

import java.util.List;

publicclass WordData{

publicstatic StringwordList="donk";

{

List wordList =new ArrayList ();

wordList.add("cat");

wordList.add("dog");

wordList.add("bird");

//blah blah

}

publicstaticvoid main( String[ ]args)

{System.out.println(WordData.wordList);

}}

[1251 byte] By [vanpersiea] at [2007-11-27 11:13:27]
# 1

No, the code you posted prints "donk."

List wordList = new ArrayList ();

That creates a new wordList variable that's local to that method and that hides the member variable.

You would have to 1) make the member variable a List, rather than a String, and 2) get rid of the "List" at the front of the line I quoted above.

jverda at 2007-7-29 14:00:59 > top of Java-index,Java Essentials,New To Java...