Re: Arraylist
- From: "Abhi" <Jboss4u@xxxxxxxxx>
- Date: 30 Jan 2007 01:51:34 -0800
Hi Chris,
I think by now John has already hlpd u a lot.....
Well, ur error was that u were returning an arraylist by-->return
cars; statement
but ur method signature was returning String-->public String addCar()
So u got this error-->C:\Java programs\AddEntry.java:20: incompatible
types
found : java.util.ArrayList<java.lang.String>
required: java.lang.String
return cars;
And if u want 2 sort etc u can use the Arrays class
Regards
import java.util.*;
import java.util.Arrays;
import java.util.Scanner;
class Car
{
public String addCar()
{
String make="";
String model="";
String year="";
ArrayList<String> cars = new ArrayList<String>();
Scanner s = new Scanner(System.in);
System.out.println("Enter make ");
cars.add(make);
System.out.println("Enter model ");
cars.add(model);
System.out.println("Enter the year ");
cars.add(year);
return cars;
}
}
.
- Follow-Ups:
- Re: Arraylist
- From: chris1980
- Re: Arraylist
- References:
- Arraylist
- From: chris1980
- Arraylist
- Prev by Date: Re: New line in a JTextArea (student learning here)
- Next by Date: Is this recursion?
- Previous by thread: Re: Arraylist
- Next by thread: Re: Arraylist
- Index(es):
Relevant Pages
|