Swap two Strings without using temp/third variable - Java Interview Questions -9

  Рет қаралды 61,734

Naveen AutomationLabs

Naveen AutomationLabs

Күн бұрын

Swap two Strings without using temp/third variable:
Algorithm:
1) Append second string to first string and
store in first string:
a = a + b
2) call the method substring(int beginindex, int endindex)
by passing beginindex as 0 and endindex as,
a.length() - b.length():
b = substring(0,a.length()-b.length());
3) call the method substring(int beginindex) by passing
b.length() as argument to store the value of initial
b string in a
a = substring(b.length());
====================================================
Subscribe to this channel, and press bell icon to get some interesting videos on Selenium and Automation:
www.youtube.co...
Follow me on my Facebook Page:
/ naveenqtpexpert
Let's join our Automation community for some amazing knowledge sharing and group discussion:
t.me/joinchat/... Subscribe to this channel, and press bell icon to get some interesting videos on Selenium and Automation:
www.youtube.co...
Follow me on my Facebook Page:
/ naveenqtpexpert
Let's join our Automation community for some amazing knowledge sharing and group discussion on Telegram:
t.me/joinchat/...
Paid courses (Recorded) videos:
Java & Selenium Course: www.naveenautom...
API Course: www.naveenautom... ➡️Get Our Courses✔️
📗 Get My Paid Courses at
Paid courses (Recorded) videos:
Java & Selenium Course: www.naveenautom...
API Course: www.naveenautom...
-------------------------------
✔️SOCIAL NETWORKS
Facebook: / naveenqtpexpert
Twitter: / naveenkhunteta
Blog: www.naveenautom...
--------------------------------
Support My Channel✔️Or Buy Me A Coffee
Paypal: paypal.me/nave...
Google Pay: naveenanimation20@gmail.com
--------------------------------
✔️Thanks for watching!
देखने के लिए धन्यवाद
Благодаря за гледането
感谢您观看
Merci d'avoir regardé
Grazie per la visione
Gracias por ver
شكرا للمشاهدة

Пікірлер: 24
@nibeditajinu
@nibeditajinu 3 жыл бұрын
Seen some of your videos.. There are other KZbinr who explained these concepts But Must say this - The way you explain ,is extraordinary, it just get typed into memory ( human Lol) and never get erased
@ckumar89
@ckumar89 6 жыл бұрын
one more: s1=s1+s2; s2=s1.replace(s2, ""); s1=s1.replace(s2, "");
@uyghurfilms3450
@uyghurfilms3450 5 жыл бұрын
How many “thank you “ is enough for your efforts? Lol thank you from my deep heart
@soumyacc4209
@soumyacc4209 Жыл бұрын
Hi Naveen, Your videos are amazing and worth watching. It gives more confidence to viewers and helps a lot to attend any interviews and apply this concept in real projects. Your framework videos are just WAW! and your way of breaking and explaining the concepts is beautiful. My best wishes to you.
@sahilkhenat1817
@sahilkhenat1817 2 жыл бұрын
I wrote little different logic by using strip function in Python and it worked. #Swap StringsPython a = "hello" b = "world" print(a,b) a = a+b difflength= len(a) - len(b) b = a[0:(difflength)] a = a.strip(b) print(a,b)
@pradeepb6914
@pradeepb6914 6 жыл бұрын
Thank you Naveen for your efforts. Solution of above using replace function String s1 = "Hello"; String s2 = "World"; // Using replace s1 = s1.concat(s2); s2 = s1.replace(s2, ""); s1 = s1.replace(s2, ""); System.out.println(s1 +" | "+s2);
@amitmoolchandani8945
@amitmoolchandani8945 6 жыл бұрын
this will not work when s1 = "HelloWorld" and s2 = "World"
@sruthitenneti3821
@sruthitenneti3821 6 жыл бұрын
we can use replaceFirst instead of replace
@Itsme1n1ly
@Itsme1n1ly 5 ай бұрын
Nice edge case ❤
@hi-ks4rl
@hi-ks4rl 6 жыл бұрын
More interview java videos will be useful.your approach is very easy to understand.
@artimandale8286
@artimandale8286 5 ай бұрын
Amazing explanation, thank you Naveen
@durdonatursunova292
@durdonatursunova292 6 жыл бұрын
Hi Neveen, Thank you for your time. All videos are very useful.
@SmartProgramming
@SmartProgramming 6 жыл бұрын
helpful tutorial, thank you, keep it up 👍👍👍👍
@gauravakash8237
@gauravakash8237 3 жыл бұрын
one more String a= "akash" String b= "Gaurav" System.out.println("The new value of a will be " + b.Substring(0) ); System.out.println("The new value of b will be " + a.Substring(0) );
@priyankagoel4448
@priyankagoel4448 4 жыл бұрын
Thank you Naveen ,it's really helpful
@clearaj710
@clearaj710 5 жыл бұрын
Can you please explain a program which is checking the drop down string values are in alphabetical order?
@elkememet701
@elkememet701 4 жыл бұрын
Thanks
@kalaimohan5421
@kalaimohan5421 2 жыл бұрын
Thank u
@sunilreddymallela
@sunilreddymallela 6 жыл бұрын
Why css selector is faster than xpath , if it is fast why most of the automation engieers are preferred to write mostly custom xpath in place of custom css selectors
@sajindraprasad
@sajindraprasad 6 жыл бұрын
Sunil Kumar Reddy Mallela css is faster but using css selector we cannot navigate forward or backward inside Dom.So xpath is used in this case
@samshoaib6871
@samshoaib6871 4 жыл бұрын
One More Way ;-) String a = "Hello"; String b = "World"; System.out.println("A: "+a); System.out.println("B: "+b); a = a+b; b=a.substring(0, 5); a=a.substring(5, 10); System.out.println("A after swapped from Hello to: "+a); System.out.println("B after swapped from World to: "+b);
@ashwinib5017
@ashwinib5017 3 жыл бұрын
This solution will work only if both strings is length 5 , Naveen s solution works for any string length
@Itsme1n1ly
@Itsme1n1ly 5 ай бұрын
It's not Scalable
final vs finally vs finalize in Java
29:21
Naveen AutomationLabs
Рет қаралды 109 М.
Java Program to Swap Two Strings Without Using Third Variable
8:50
Nurse's Mission: Bringing Joy to Young Lives #shorts
00:17
Fabiosa Stories
Рет қаралды 15 МЛН
Фейковый воришка 😂
00:51
КАРЕНА МАКАРЕНА
Рет қаралды 6 МЛН
Cute kitty gadgets 💛
00:24
TheSoul Music Family
Рет қаралды 21 МЛН
What does Satoru Gojo have? #cosplay#joker#Harley Quinn
00:10
佐助与鸣人
Рет қаралды 7 МЛН
FASTEST Way to Learn Coding (for FREE) and ACTUALLY Get a Job
8:32
PIRATE KING
Рет қаралды 1 МЛН
"I Hate Agile!" | Allen Holub On Why He Thinks Agile And Scrum Are Broken
8:33
Automating My Life with Python: The Ultimate Guide | Code With Me
11:26
Java Program to Count Number of Duplicate Words in Given String
16:40
Naveen AutomationLabs
Рет қаралды 61 М.
Find Duplicate Elements in An Array || Important Java Interview Questions
22:36
Naveen AutomationLabs
Рет қаралды 51 М.
I Learned Java in 14 Days using THIS Framework (learn any language!)
14:21
Internet Made Coder
Рет қаралды 202 М.
Why String is Immutable and Final in Java?
19:59
Naveen AutomationLabs
Рет қаралды 87 М.
I learned to code from scratch in 1 year. Here's how.
41:55
Thomas Frank
Рет қаралды 406 М.
Nurse's Mission: Bringing Joy to Young Lives #shorts
00:17
Fabiosa Stories
Рет қаралды 15 МЛН