Answer the question
In order to leave comments, you need to log in
How to perform actions on elements with ArrayList?
Hello, I read the array using list.add(tf_name.getText()), I want to perform some actions in the loop then, let's find min, max, etc., in the console it was done like this arr[i] < 0 etc. And I have a sheet, and, as I understand it, I don’t have such an array. Thanks in advance for the help
that I wrote myself:
public class Controller {
ArrayList<String> list = new ArrayList<>();
@FXML
TextField tf_name;
@FXML
Label lb_one;
@FXML
private void onClick(ActionEvent event){
list.add(tf_name.getText());
String s = "";
for (int i = 0; i < list.size(); i++){
s = list.get(i) + s;
}
for (int i = 0; i < list.size(); i++) {
System.out.println(s + " ");
}//String s = tf_name.getText();
//lb_one.setText(s);
}
}
Answer the question
In order to leave comments, you need to log in
If you need a way to loop through a List, you can also use a simple for. You can also use forEach.
for (String num : list){
s += num + " ";
}
List<String> list = Arrays.asList(tf_name.getText().split(" "));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question