Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

285
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda