954,536 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

ArrayList as an an attribute

Hi,
I'm trying to do something pretty straightforward (I think) but it's not working for me for some reason. Basically trying to create an object with an ArrayList as a attribute but i keep getting numerous errors saying ' expected', '; expected'.

My code is as follows:

import java.util.ArrayList;

public class testALObject

{


public String surname;
public ArrayList<String>() firstname;

public testALObject()
	{

	}

}


I haven't even put anything in the constructor as can't get past the first line. I've coded plenty of Objects before but never used an ArrayList so can't figure out where I'm going wrong?

Any help would be greatly appreciated!

spaniel
Newbie Poster
3 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
 

the error is here:

public ArrayList<String>() firstname;

replace it with:

public ArrayList<String> firstname;
moutanna
Posting Whiz
387 posts since Oct 2009
Reputation Points: 16
Solved Threads: 58
 

Thanks, I actually spent about 40 minutes trying to fix this before posting the above then solved it 5 minutes later. Tried to delete the post and then couldn't. Thanks for helping!

spaniel
Newbie Poster
3 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You