Re: Arraylist



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;
}

}



.



Relevant Pages

  • Re: Serialization of a custom collection
    ... it seems I'll have to create a "wrapper" ... public class CarCollection: List ... public string Model; ... CarCollection cars = GetCars; ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: web service error - urgent
    ... What about this instead (return an array of Cars): ... Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id) ... public string make; ...
    (microsoft.public.dotnet.framework.webservices)
  • RE: web service error - urgent
    ... What is "ports" anyway? ... What about this instead (return an array of Cars): ... Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id) ... public string make; ...
    (microsoft.public.dotnet.framework.webservices)
  • Re: Datagrid and switch
    ... public string ConvertFieldType(int fieldTypeId){ ... > If it is a 1 it must show cars. ... > If it is a 2 is must show bikes. ...
    (microsoft.public.dotnet.framework.aspnet)
  • How do I create a class item with properties?
    ... A class called Cars ... public string Mazda; ...
    (microsoft.public.dotnet.general)