Can't print out String array element!

How do you usually print a String element in an array,

I use

System.out.println(array[ i ]);

and the attay is defined and initialized as,

String array[] = null;

It's worth mentioning that in a for loop I construct a String "temp" variable which gets filled in like the following!  I can print out temp but I get a NullPointerException when I try to print the array version of this!

for (;;) {
                data = bufIn.read();
                // Check for EOF
                if (data == -1) {
                    break;
                } else {
                    temp = temp + (char) data;
                }
            }
snajalmAsked:
Who is Participating?
 
evedderConnect With a Mentor Commented:
well as far as i know arrays in java can not be dynamic, for that you need to use a Collection, so in your code you need to initialize your array with some elements or you can initialize it as null but then you need to assign another array later.

I would use an ArrayList instead of an array

List<Character> array = new ArrayList<Character>();

array.add( new Character(data))

System.out.println(array.get(i);
0
 
snajalmAuthor Commented:
Well done!  Thanks heaps!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.