Hi everyone,

I have small Problem. I have to take input as a string say blue,green,red, etc split this into blue green red respectively separately and then add those into an ArrayList Clr.

I have written

System.out.println(" Enter Color ");

String input = br.readLine();

ArrayList clr = new ArrayList();

String c [] = input.split(",");



where pd is the object of the class and ar is the Arraylist and clr is the ArrayList within an ArrayList.

i know its wrong but not able to figure out the logic behind that. could anybody help me pl ?

Thanks in advance! :)

Recommended Answers

All 2 Replies

You need to specify what type of ArrayList you are using. You cannot declare your variable that way. You should read the ArrayList API doc. The way you use is

ArrayList<E> variableName = ArrayList<E>();

where E is a type of java object class and cannot be primitive (int, long, double, etc.).

ArrayList<Integer> myIntArray = new ArrayList<Integer>();

the ArrayList is of the type <Product> where Product is the class which has Product Id,Product Name, Size, Color.

class Product {

	private String pid;

	private String name;

	private String size;

	private ArrayList color;

	public ArrayList getColor() {

	return color;


	public void setColor(ArrayList color) {

	this.color = color;


	public String getPid() {

	return pid;


	public String getName() {

	return name;


	public String getSize() {

	return size;


	public void setPid(String pid) {

	this.pid = pid;


	public void setName(String name) {

	this.name = name;


	public void setSize(String size) {

	this.size = size;


}  // Class Product Ends Here
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.