Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to save a string value in an array?

807601Feb 13 2008 — edited Feb 14 2008
I'm just trying to save a user input as a string into an array using JOptionPane. Pretty simple, I'm sure, but I can;t find anything about it in my books or online. Any help?
for(int index = 0; index < numNames; index ++)

int[] firstName = new int[numNames]; //array of first names
int[] lastName = new int[numNames]; //array of last names

String firstName = JOptionPane.showInputDialog("Enter the first name of person #" + (index + 1) + ");
firstName[index] = keyboard.nextString;
String lastName = JOptionPane.showInputDialog("Enter the last name of person #" + (index + 1) + ");
lastName[index] = keyboard.nextString;
I know that's how I would do it if i were using Scanner and not JOptionPane, but I'm just showing you guys what I want to do. Just basically save the first name into one array and the last name into another array. Thanks for the help!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 13 2008
Added on Feb 13 2008
14 comments
263 views