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

284
Views
String Cannot Be Converted To Int

This is just a little bit of my code, but I am trying to loop through two strings, get the value of the first number in one string, and then use that number as the position to find in the other string, then add that word into a new string. But it comes up with the error "String cannot be converted to int" can anyone help?

        String result = "";   

        for (int i = 0; i < wordPositions.length; i++){
           result += singleWords[wordPositions[i]];
        }     
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Use this to convert String into int

Integer.parseInt(integerString);

The completed line of code:

result += singleWords[Integer.parseInt(wordPositions[i])];
over 4 years ago · Santiago Trujillo Report

0

if your wordPositions is a String array when you do this:

  result += singleWords[wordPositions[i]];

it like if you does this

result += singleWords["value of the wordPositions array at index i"];

but is need to be an int in [] not a string that why you have the exception String can not be cast to Int

over 4 years ago · Santiago Trujillo Report

0

If wordPositions is an array of numbers inside a string for example

String[] wordPositions = new String[]{"1","2","3"};

Then you nees to use

Integer.parseInt(NUMBER_IN_STRING);

To change the string value to an int value.

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!