how to convert string to int in Java

This question already has an answer here:

  • How do I convert a String to an int in Java? 30 answers
  • How do I convert from int to String? 19 answers

  • Ask following questions to your self first.

  • What your method want as parameter?
  • Why both are Incompatible?
  • What String cipherText = cc.encrypt(plainText,key); mean?
  • key is String or int ?
  • Use methods like Integer.parseInt(String value) or Integer.valueOf(String value) for conversion.


    It seems like you need to convert a String to int , not a int to String . To do that, you can use Integer.parseInt() :

    int someInt = Integer.parseInt(someString);
    

    You are passing String and the method parameter seems to have int and hence the error. You might want to convert your string to int using int keyInt = Integer.parseInt(key); and similarly for plain text if necessary and then pass keyInt and/or plainTextInt as the parameters.

    链接地址: http://www.djcxy.com/p/20924.html

    上一篇: Java:将字符串转换为Int(未知源)

    下一篇: 如何在Java中将字符串转换为int