Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to compare characters between two strings?

 
rahul S Sharma
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,
I am a beginner in java. My question is suppose two strings s1 and s2 are given.
String s1="bcd";
String s2="abc bcd def efg";
and its output should be aefg....
So please tell me how can i achieve this output...
thanks in advance...
 
Siddhesh Deodhar
Ranch Hand
Posts: 118
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use toCharArray() and conatins() method's of String class and achieve your goal.
Check their usage in Java docs.
 
vinayak jog
Ranch Hand
Posts: 83
MySQL Database Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello ranch
As siddhesh said
 
Luigi Plinge
Ranch Hand
Posts: 441
IntelliJ IDE Scala Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Should work.

Or in Scala
 
vinayak jog
Ranch Hand
Posts: 83
MySQL Database Netbeans IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
awesome logic man Luigi Plinge
 
Campbell Ritchie
Sheriff
Pie
Posts: 49382
62
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
vinayak jog wrote:awesome logic man Luigi Plinge . . .
But you have both done nothing to help rahul S Sharma. Rather you have deprived him of the opportunity of learning how to do it for himself, and maybe done more harm than good
 
fred rosenberger
lowercase baba
Bartender
Posts: 12145
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will continue to delete any code provided that simply gives the answer to a homework problem.

Please resist the temptation to GIVE the answer out. We are here to TEACH people how to get the answer themselves.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49382
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fred rosenberger wrote:I will continue to delete any code provided that simply gives the answer to a homework problem.

Please resist the temptation to GIVE the answer out. We are here to TEACH people how to get the answer themselves.
I left the code myslef because I thought it was too late to delete it.
 
Pankaj Kumarkk
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I haven't seen what other people have suggested thus what I suggest may be same. If it is then please ignore my post.
One approach could be by taking s1 and removing occurrence of all s1’s characters from s2. Thus what you get after this removal would be the output you are looking for.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic