Add string var to a String array

I have this String array:String[] names = {"Mike", "Paul"};How would I add a name called "Bob" for instance to 'names' ?Thanks,JavaHarlin
[174 byte] By [JavaHarlina] at [2007-11-27 6:38:07]
# 1

> How would I add a name called "Bob" for instance to

> 'names' ?

You can't. An array's size is fixed at creation time.

You can:

1) Replace an existing entry.

2) Create a new larger array, copy the existing elements into it, and then put the new entry into the last slot.

3) Use a Collection, such as an ArrayList or LinkedList.

http://java.sun.com/docs/books/tutorial/collections/

Not knowing your requirements or what you're really trying to do, my initial inclination would be #3.

jverda at 2007-7-12 18:06:41 > top of Java-index,Java Essentials,Java Programming...
# 2

Im trying this from this page i found: http://www.developer.com/java/other/article.php/3343771

I tried this:

List ips = new ArrayList();

When I do that I get this error from the compiler:

FileInOut.java:8: cannot find symbol

symbol : class List

location: class FileInOut

List ips = new ArrayList();

^

FileInOut.java:8: cannot find symbol

symbol : class ArrayList

location: class FileInOut

List ips = new ArrayList();

^

2 errors

Any reason why this doesn't work?

Thanks,

Harlin

JavaHarlina at 2007-7-12 18:06:41 > top of Java-index,Java Essentials,Java Programming...
# 3
Did you import java.util.List and java.util.ArrayList ?
kdajania at 2007-7-12 18:06:41 > top of Java-index,Java Essentials,Java Programming...
# 4
http://java.sun.com/docs/books/tutorial/java/package/usepkgs.html
jverda at 2007-7-12 18:06:41 > top of Java-index,Java Essentials,Java Programming...
# 5
Argh! Thank you very much... like so:import java.util.*; ?Thanks,JavaHarlin
JavaHarlina at 2007-7-12 18:06:41 > top of Java-index,Java Essentials,Java Programming...