Need help with Java Strings

Dear fellow Java developers:

I am having problems with a java problem.  I have a method:

public String removeString(String firstString, String secondString)

The purpose of this method is to remove the characters in "firstString", and remove it from "secondString".  For example, if "firstString" is "aeiou", and "secondString" is "Hello World", the resulting string should be "Hll Wrld".  

How would I do this?

Thanks in advance to all who reply.
fsyedAsked:
Who is Participating?
 
for_yanConnect With a Mentor Commented:

This is how it work.
Let me know if you don't understand anything I'll explain

public class GetNewString{

    public static String getString(String firstString, String secondString){

    StringBuffer sb = new StringBuffer();
for(int j=0;j<secondString.length();j++){
if(firstString.indexOf(secondString.charAt(j)+"") == -1)sb.append(secondString.charAt(j));


}
  return sb.toString();

}

  public static void main(String[] args) {

        
               System.out.println(getString ("aeiou", "Hello World"));
}
}

Open in new window


Ouptput:

Hll Wrld

Open in new window

0
 
for_yanCommented:
Somethidn like that:


StringBuffer sb = new StringBuffer();
for(int j=0,j<secondString.length();j++){
if(firstString.indeOf(secondString.charAt(j)+"") > -1)sb.add(secondString.charAt(j);


}

Systerm.out.println(sb.toString())

Open in new window

0
 
for_yanCommented:
rahter opposite:

StringBuffer sb = new StringBuffer();
for(int j=0,j<secondString.length();j++){
if(firstString.indeOf(secondString.charAt(j)+"") == -1)sb.add(secondString.charAt(j);


}

Systerm.out.println(sb.toString())

Open in new window

0
 
fsyedAuthor Commented:
Thanks very much for your help.  Your solution worked!  Points well deserved.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.