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

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

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

  • @JavaGuides
    @JavaGuides  4 หลายเดือนก่อน

    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 4 หลายเดือนก่อน +2

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

  • @prof.mangabhai
    @prof.mangabhai 4 หลายเดือนก่อน +2

    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)

  • @Maruthi468
    @Maruthi468 4 หลายเดือนก่อน

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

  • @VasyaFF
    @VasyaFF 4 หลายเดือนก่อน +1

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

  • @Yaduvanshi-nw3yr
    @Yaduvanshi-nw3yr 4 หลายเดือนก่อน

    Another way using recursion method

  • @randomstranger8326
    @randomstranger8326 4 หลายเดือนก่อน

    Can you make one using stack ds?

  • @guohaofrankwu7317
    @guohaofrankwu7317 4 หลายเดือนก่อน

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

  • @phusicus_404
    @phusicus_404 4 หลายเดือนก่อน +1

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

    • @JavaGuides
      @JavaGuides  4 หลายเดือนก่อน

      You show me efficient approach

    • @nabinghoshmaths6834
      @nabinghoshmaths6834 4 หลายเดือนก่อน

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

    • @JavaGuides
      @JavaGuides  4 หลายเดือนก่อน +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 4 หลายเดือนก่อน

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

    • @aribasiebel
      @aribasiebel 4 หลายเดือนก่อน

      Solve it recursively. It's most efficient 😂