Shouldn't "list" be a parameter of the method Create()?
PHP Code:
static LinkedList<People> Create(String nameFile)
throws IOException
{ LinkedList<People> list = new LinkedList<People>();
boolean Fileexists = true ;
FileReader fi = null;
try {
fi = new FileReader (nomFichier) ;
}
catch ( java.io.FileNotFoundException erreur) {
System.out.println("Probleme d'ouvrir le fichier " +
nameFile);
Fileexists = false ;
}
if (Fileexists) {
BufferedReader enter = new BufferedReader(fi);
boolean endFile = false ;
while ( !endFile ) {
String aLine = enter.readLine();
if (aLine == null)
endFile = true ;
else {
String name = aLine.substring(0, 10);
char sex = aLine.charAt(30);
double height = Double.parseDouble(aLine.substring(37, 41));
double weight = Double.parseDouble(aLine.substring(51, 56).trim());
int number = Integer.parseInt(aLine.substring(64));
liste.add(new People(name, sex, height, weight, number));
}
}
enter.close();
}
return list;
}
Re: Shouldn't "list" be a parameter of the method Create()?
Please explain your question.
Re: Shouldn't "list" be a parameter of the method Create()?
Since we return list, shouldn't list be a parameter of the method create()?
I thought we'd have to write: "create(String nameFile, List[] list)" or something similar.
Re: Shouldn't "list" be a parameter of the method Create()?
It all depends on what the create method is supposed to do. With a name like: create, I'd assume that it would create the list and return it It would not be a parameter to the method. A method named: update() might take a list as a parameter.
Re: Shouldn't "list" be a parameter of the method Create()?
Wait, I think I remember now... You don't need to declare it if it's an array that's returned, only if it's an integer double or a string and so on. Right?
Re: Shouldn't "list" be a parameter of the method Create()?
It all depends on what the method is supposed to do.
Re: Shouldn't "list" be a parameter of the method Create()?
Quote:
Originally Posted by
wholegrain
Wait, I think I remember now... You don't need to declare it if it's an array that's returned, only if it's an integer double or a string and so on. Right?
Why do you mean, "don't need to declare".
Clarify please.