Click here to Skip to main content
15,884,425 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
for example i add the childname and their details now i want to remove specific child so how can i do it in java?

What I have tried:

public String removeChild(String ChildName)
  {

      for (int i = 0; i < childList.length; i++)
          if (childList[i].equals(ChildName))
              return removeChild(i);
      return null;
Posted
Updated 2-Apr-18 22:22pm
Comments
wseng 3-Apr-18 0:28am    
http://www.java67.com/2012/12/how-to-remove-element-from-array-in-java-example.html
Patrice T 3-Apr-18 0:58am    
is it an array of strings or an array of objects ?

 
Share this answer
 
If in your code childList is an array of string, this might help you:
Java
import java.util.Arrays;
import org.apache.commons.lang.ArrayUtils;

string[] childList = new string[];

/// Remove given ChildName from Array
/// returns the removed ChildName, null if nothing removed
public String removeChild(String ChildName)
{
  for (int i = childList.length-1; i >= 0; i--)
  {
    if (childList[i].equals(ChildName))
    {
      childList = ArrayUtils.remove(childList, i);
      return ChildName;
    }
  }
  return null;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900