Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

193
Vistas
How to store string arrays inside a for & for-each iteration

Here are for loopand for (Element link : links)loopings . I want to store every elements title to line[]

What should I do ?

   String[] line = new String[100];

     for (int i = 0; i < numberOfResultpages; i++) {

             ......

                for (Element link : links) {

                    String title = link.text();
                    String url = link.absUrl("href"); 
                    url = URLDecoder.decode(url.substring(url.indexOf('=') + 1, url.indexOf('&')), "UTF-8");

                    if (!url.startsWith("http")) {
                        continue; // 
                    }
                    System.out.println("Title: " + title);


                    line[ numberOfResultpages ]=title;  //I don't know how to store every title element into line here 
               // }

        }
             }

Update

numberOfResultpages is not the maximum size of the array a numberOfResultpages can have many elementtitle

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

String[] line = new String[numberOfResultpages * links.size()]; // assign adequate size to line array.

int idx = 0;
for (int i = 0; i < numberOfResultpages; i++) {

    ...
    for (Element link : links) {
       ...
       line[idx++]=title;
over 4 years ago · Santiago Trujillo Denunciar

0

Try By using ArrayList:

List<Strng> list=new ArrayLst<String>();
 for (int i = 0; i < numberOfResultpages; i++) {
   .........
//Every thing same
//add like this, ArrayList is Dynamic in Size
list.add(title);
} }
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda