Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

178
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!