How to store string type data in a java array

1

Good People I need help, I am working on a project with forms, the program is already done, it is about a questionnaire in which it presents a question (jlabel) and the user chooses one of the options shown by (radiobutton), until the system hits a final answer.

What I want is to add a button that I printed in a textarea the route of the questions that were made to reach such a response. Ex.

  pregunta1

  pregunta4

  pregunta5

  pregunta6

  respuesta

Assuming those were the questions to which the user answered "Yes".

ok sorry I am new, in order if they could help me what I want is to create a button that when pressed press the route of a tree. but I need to know how to store a string type data generically and then print them in a textarea. Thanks!

Thanks @David I always use your knowledge, now I have a question, when I print the information, I print the data separated by "," and enclosed between "[]" how can I omit those characters ?? Ejm: [Red, Green, Blue, Gray] , but what I really want is this - >

Rojo
Verde
Azul
Gris

I would also like you to help me in how to know if a button has been pressed, try using a variable type boolean initializing to false and within the Mousclicked of the button to put it true, but how do I reset it to false.

    
asked by Jesus Duarte 13.08.2017 в 23:44
source

1 answer

1

If you want to store String values in an Arrangement, it is as simple as the following:

Array

// Aqui los valores se introducen al declarar el arreglo.
String[] frutas = {"mango", "uva", "pera", "manzana"};

// Aqui los valores se introducen despues de declarar el arreglo. 
// Este es un arreglo de 4 posiciones, el numero de elementos que puede  
// almacenar se declara en la instancia de este.
String[] nombres = new String[4];
nombres[0] = "Jose";
nombres[1] = "Pedro";
nombres[2] = "Juan";
nombres[3] = "Rafael";

ArrayList

Remember to import the library:

import java.utils.ArrayList;

.

ArrayList<String> lacteos = new ArrayList<String>();

lacteos.add("Leche");
lacteos.add("Mantequilla");
lacteos.add("Queso");
lacteos.add("Yogour");

One of the difference between an ArrayList and an Array, is that an ArrayList can store values dynamically, so it is not necessary to define the number of positions it will possess when declaring it. Another difference is that an ArrayList has methods that allow you to manipulate lists more easily.

    
answered by 14.08.2017 / 19:59
source