4 Ways to Convert String to Int in Java

แชร์
ฝัง
  • เผยแพร่เมื่อ 9 พ.ย. 2024

ความคิดเห็น • 45

  • @TalentedDeveloper
    @TalentedDeveloper  3 ปีที่แล้ว +2

    ⭐ Kite is a free AI-powered coding assistant that will help you code faster and smarter. The Kite plugin integrates with all the top editors and IDEs to give you smart completions and documentation while you’re typing. I've been using Kite for 6 months and I love it! www.kite.com/get-kite/?

  • @Aryabarta-ghxy
    @Aryabarta-ghxy 5 ปีที่แล้ว +3

    What's the difference among these 4 ways and which one to use when?

    • @TalentedDeveloper
      @TalentedDeveloper  5 ปีที่แล้ว +2

      All are the ways, you can use any one.
      There is no any condition that you have to use 1 way in this condition like that.
      These are the 4 ways, suppose if you forget one way then you can use other ways.
      Thanks @sujoy

  • @ezequielschmit
    @ezequielschmit 3 ปีที่แล้ว +1

    Hi bro, great video... what if I have "5+3*2" in a String...how do I convert it to an integer and how do I solve it?
    Greetings from Argentina!

    • @TalentedDeveloper
      @TalentedDeveloper  3 ปีที่แล้ว +1

      Hola, Buenos días.
      There are so many solutions, java 9 they have introduced some feature.
      but if you are using JDK 1.6 and greater than then use this
      ScriptEngineManager manager = new ScriptEngineManager();
      ScriptEngine engine = manager.getEngineByName("js");
      String question = "5+3*2";
      System.out.println(engine.eval(question));
      This is just a way, not a permanent solution.
      Check below
      stackoverflow.com/questions/3422673/how-to-evaluate-a-math-expression-given-in-string-form

    • @ezequielschmit
      @ezequielschmit 3 ปีที่แล้ว +1

      @@TalentedDeveloper muchísimas gracias por la respuesta!

    • @TalentedDeveloper
      @TalentedDeveloper  3 ปีที่แล้ว

      Eres muy bienvenido

  • @rickykapoor9218
    @rickykapoor9218 3 ปีที่แล้ว +2

    Why it is necessary to convert it to int?? Plzzz tell

    • @TalentedDeveloper
      @TalentedDeveloper  3 ปีที่แล้ว +1

      hi,
      it is not necessary, but sometime you will have any data as a string but during some process you need the data as int, so on that time it need to be converted.
      It can be string to int,vice versa

    • @rickykapoor9218
      @rickykapoor9218 3 ปีที่แล้ว +2

      @@TalentedDeveloper thanks man this is really appreciated
      Subscribed

    • @TalentedDeveloper
      @TalentedDeveloper  3 ปีที่แล้ว

      most welcome 😃

  • @smileymcgee6584
    @smileymcgee6584 4 ปีที่แล้ว +2

    How about converting int to string?

    • @TalentedDeveloper
      @TalentedDeveloper  4 ปีที่แล้ว +1

      Please check this: th-cam.com/video/UdojiH7NWAE/w-d-xo.html

  • @6RZA
    @6RZA ปีที่แล้ว

    w tutorial
    thnk u so much

  • @animepaithiyam6872
    @animepaithiyam6872 2 ปีที่แล้ว

    Nice explanation

  • @yasminalazizi9399
    @yasminalazizi9399 3 ปีที่แล้ว

    Thank you so much sir very good video best of luck with your career

  • @aichuliam4139
    @aichuliam4139 ปีที่แล้ว

    thank you

  • @zahraaneila1674
    @zahraaneila1674 3 ปีที่แล้ว +1

    how about from double to string

    • @TalentedDeveloper
      @TalentedDeveloper  3 ปีที่แล้ว +1

      Hi, you can use String.valueOf()
      like
      double d=44.2;
      String s=String.valueOf(d);

    • @zahraaneila1674
      @zahraaneila1674 3 ปีที่แล้ว +1

      @@TalentedDeveloper thank you so much, so helpful!!

    • @TalentedDeveloper
      @TalentedDeveloper  3 ปีที่แล้ว

      you are most welcome 😃

  • @Ravengal101
    @Ravengal101 5 ปีที่แล้ว +1

    How do I convert an array of strings into an array of integers?

    • @TalentedDeveloper
      @TalentedDeveloper  5 ปีที่แล้ว +1

      just run for loop and use parseInt and store into new array.
      Example:
      String [] str = {"12", "34", "56"};
      int size = str.length;
      int [] arr = new int [size];
      for(int i=0; i

    • @Ravengal101
      @Ravengal101 5 ปีที่แล้ว +2

      Talented Developer Thanks for the quick response! That’s what I figured out. 😊

    • @TalentedDeveloper
      @TalentedDeveloper  5 ปีที่แล้ว

      Most welcome.
      Great, keep going on. 😀

  • @samahalz
    @samahalz 5 ปีที่แล้ว +1

    Thank you so much ❤

  • @isaacfrankental4040
    @isaacfrankental4040 4 ปีที่แล้ว +1

    What if I want variable in JSP to receive a value from an input text in HTML.?

    • @TalentedDeveloper
      @TalentedDeveloper  4 ปีที่แล้ว +1

      Hi @Isaac, create a function that will convert string to int. That function call in input text in html.
      or you can use parseint () in JavaScript also

  • @alouanewailzineddine6186
    @alouanewailzineddine6186 4 ปีที่แล้ว +1

    What if my string is "33 55" so I have 2 numbers how can I get the tow numbers

    • @TalentedDeveloper
      @TalentedDeveloper  4 ปีที่แล้ว +1

      if you want the number as 33 and 55 seperately then try to use split method on the basis of space.
      so you will get two number at the index of 0 and 1.
      after that you can use.
      Please let me know if you have any questions

    • @alouanewailzineddine6186
      @alouanewailzineddine6186 4 ปีที่แล้ว +1

      @@TalentedDeveloper thank u so much i used this method I found it .. ur video helped me loot , thaank u

    • @TalentedDeveloper
      @TalentedDeveloper  4 ปีที่แล้ว

      Alouane Wail Zineddine most welcome😀👍

  • @ccm3411
    @ccm3411 5 ปีที่แล้ว +1

    Nice english my friend

    • @TalentedDeveloper
      @TalentedDeveloper  5 ปีที่แล้ว

      are you kidding or appreciating ??🤪

    • @ccm3411
      @ccm3411 5 ปีที่แล้ว +1

      @@TalentedDeveloper Respectfully kidding man, where are you from tho. Greeting from Mexico and nice video

    • @TalentedDeveloper
      @TalentedDeveloper  5 ปีที่แล้ว +2

      😀... Thanks 😜... Greeting from India🇮🇳

  • @hastokegharbaste8021
    @hastokegharbaste8021 2 ปีที่แล้ว

    I can't see anything
    .

  • @convergentradius
    @convergentradius 4 ปีที่แล้ว +1

    70th like. not nice

    • @TalentedDeveloper
      @TalentedDeveloper  4 ปีที่แล้ว

      sorry for bad experience, can you tell me what you don't like?