3
I’m trying to break the following ArrayList
with a String
:
ArrayList<Funcionario> funcionarios = new ArrayList();
But when I instate the object, I add the values inside through my method and try to use the split
, the compiler underlines the .split
in red and gives error. I’m trying to separate the information by a space " "
.
Funcionario func = new Funcionario(); //Instancio o obj
func.cadastrar(); //CHama o método que lê o teclado
funcionarios.add(func); // Manda pro ArrayList
System.out.println("\n\n\nFuncionario cadastrado: \n" + func.toString()); //Mostra o que foi adicionado
System.in.read();
func.gravar(); //Salva em um txt
String[] separado = funcionarios.split(" "); //Aqui dá erro
Someone knows what the mistake is?
I want to separate the entries for each employee (name, email, phone, salary) in String
s separate.
I want to break into String
s to be able to add in a vector, sort and then create a ArrayList
by name (in one of the application options) or salary (another part of the code).
Thank you
public String toString()
{
return "\nNome: " + nome
+ "\nEmail: " + email
+ "\nTelefone: " + telefone
+ "\nSalario: R$ " + salario ;
}
You want a list of employees or a list of employee names?
– Victor Stafusa
You should have posted the error. But in this case, the error is obvious: there is no method
ArrayList.split
.– Vinícius Gobbo A. de Oliveira
What is the purpose of
System.in.read();
isolated in the middle?– Victor Stafusa
The System.in.read(); is to pause the screen, otherwise it passes straight. This process is inside a while
– Evilmaax
You want a list of employees or a list of employee names?
– Victor Stafusa
Opa @Victorstafusa I want to separate the entries for each employee (name, email, phone, salary) in separate strings.
– Evilmaax
@This completely changes your question. In this case, this type of information should be present in the body of the question, otherwise you will end up not getting the answers you seek.
– Victor Stafusa
How is the method
toString()
classFuncionario
?– Victor Stafusa
You want 4 Arrays, one with the names other with the email etc?
– ramaral
@Victorstafusa I added toString() used
– Evilmaax
@ramaral This. I want to break into strings to be able to add in an array, sort and then be able to create an Arraylist sorted by name (in one of the application options) or salary (another part of the code).
– Evilmaax
You are already using JAVA 8?
– ramaral