How to Remove a content of second String from First String

How to Remove a content of second String from First String.
SOURCE : RemoveFromSecond.java

public class RemoveFromSecond {

public static void main(String[] args) {
String first = "arpit";
String second = "tp";
boolean bit[] = new boolean[256]; // boolean are defaulted to false

for (int i = 0; i < second.length(); i++) {
bit[second.charAt(i)] = true;
}

char[] result = new char[first.length() - second.length()];

for (int i = 0, j = 0; i < first.length(); i++) {
if (bit[first.charAt(i)] == false) {
result[j] = first.charAt(i);
j++;
}

}

String resultstr = new String(result);
System.out.println("Result : " + resultstr.toString());
}

}


INPUT

String first = "arpit";
String second = "tp";



OUTPUT

Result : ari






Sandeep Kumar D

Hi, I have written and developed this post so that most of people will be benefited. I'm committed to provide easy and in-depth tutorials on various technologies.I hope it will help you a lot.

- Sandeep Kumar D

Follow Me @Google+




SHARE

    Blogger Comment
    Facebook Comment

0 comments :

Post a Comment