Results 1 to 2 of 2
Thread: string arrays and copying
- 11-18-2012, 05:23 AM #1
Member
- Join Date
- Nov 2012
- Posts
- 5
- Rep Power
- 0
string arrays and copying
getfullname is a method that contains all the names....my problem is is it wont allow me to add the getfullname into the string array getanames or is there an easier way to copyJava 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++) { getNames.add(list.get(i).getFullName()); }
-
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
-
Copying Single Arrays to 2-D Arrays
By jmscarlet9 in forum New To JavaReplies: 7Last Post: 04-02-2012, 11:17 PM -
How do you use an arraylist of string arrays
By uhertz in forum New To JavaReplies: 1Last Post: 01-16-2012, 09:38 AM -
copying a part of a string and moving it to the end of the string?
By sidd0123 in forum New To JavaReplies: 9Last Post: 04-23-2010, 01:52 AM -
String arrays
By myka in forum New To JavaReplies: 1Last Post: 03-18-2010, 07:49 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks