Java Program to Reverse String without using in-built reverse() Method

Поделиться
HTML-код
  • Опубликовано: 18 сен 2024

Комментарии • 15

  • @JavaGuides
    @JavaGuides  6 месяцев назад

    Note: If you use StringBuilder then you can use it's reverse method to reverse the string.
    It does not make sense to create StringBuilder object to just append small String. Even interviewer may ask you reverse a string without using any built-in reverse methods or additional classes like StringBuilder or StringBuffer.
    Use StringBuilder for concatenating or appending long strings. This can be a most efficient way to reverse a string in Java without build-in method

  • @thatguyadarsh
    @thatguyadarsh 7 месяцев назад +2

    Little modification: we can use stringbuilder instead of concatenation.
    Thanks for your videos!! 😊

  • @Maruthi468
    @Maruthi468 6 месяцев назад +1

    Use StringBuilder with append instead of result = result + i-value

  • @prof.mangabhai
    @prof.mangabhai 6 месяцев назад +3

    in a interview this wouldn't be satisfactory, since everytime we are making a new string when concating a new character, so for super large strings it is not advised to use this method, use a stringbuilder or a char[] (which can be later converted to string by toString() method)

  • @VasyaFF
    @VasyaFF 6 месяцев назад +2

    Is this a better way to use: `i >= input.length / 2` and each iteration swap first and last chars?

  • @luncsffrfun-ch1zf
    @luncsffrfun-ch1zf 10 дней назад

    How to use the Exception hamdling??

  • @Kamrankhan23333
    @Kamrankhan23333 6 месяцев назад

    Can you make one using stack ds?

  • @guohaofrankwu7317
    @guohaofrankwu7317 7 месяцев назад

    is the time complexity Big-O O(n)? if using reverse can reduce the time complexity

  • @Yaduvanshi-nw3yr
    @Yaduvanshi-nw3yr 6 месяцев назад

    Another way using recursion method

  • @phusicus_404
    @phusicus_404 6 месяцев назад +1

    You've chosen the most inefficient approach. Delete the video and think of what you have done.

    • @JavaGuides
      @JavaGuides  6 месяцев назад

      You show me efficient approach

    • @nabinghoshmaths6834
      @nabinghoshmaths6834 6 месяцев назад

      ​@@JavaGuides May be we can use Stringbuffer to append the character. But this way is also fine.

    • @JavaGuides
      @JavaGuides  6 месяцев назад +1

      If you use StringBuilder then you can use it's reverse method to reverse the string.
      It does not make sense to create StringBuilder object to just append small String. Even interviewer may ask you don't use any other classes and in-built methods other than String.

    • @phusicus_404
      @phusicus_404 6 месяцев назад

      @@JavaGuidesSwap characters from both halves of the string from the ends to the middle.
      It was among the comments.

    • @aribasiebel
      @aribasiebel 6 месяцев назад

      Solve it recursively. It's most efficient 😂