Results 1 to 2 of 2
  1. #1
    ztomtomz is offline Member
    Join Date
    Nov 2012
    Rep Power

    Default string arrays and copying

    Java Code:
    String[] getNames()
       // Creates a string array containing the full name of each staff member
           String[] getNames = new String[10];
           for(int i = 0; i < 3; i++)
    getfullname is a method that contains all the problem is is it wont allow me to add the getfullname into the string array getanames or is there an easier way to copy

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power

    Default Re: string arrays and copying

    You're trying to add something to an array as if it were an ArrayList. It's not, and arrays do not have an .add(...) method. You instead simply assign the String of interest to the [ith] item in the array using array [...] notation.

    Another big problem I see is your use of the magic numbers 10 and 3 in that code.

Similar Threads

  1. Copying Single Arrays to 2-D Arrays
    By jmscarlet9 in forum New To Java
    Replies: 7
    Last Post: 04-02-2012, 11:17 PM
  2. How do you use an arraylist of string arrays
    By uhertz in forum New To Java
    Replies: 1
    Last Post: 01-16-2012, 09:38 AM
  3. Replies: 9
    Last Post: 04-23-2010, 01:52 AM
  4. String arrays
    By myka in forum New To Java
    Replies: 1
    Last Post: 03-18-2010, 07:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts