-1

I'm making a project in Java and am passing an object through another classes function. This object contains a Linkedlist of objects. If I delete one of these objects within the other class, will it only be deleting a copy of it, or will it be passing by reference?

This is the example of my delete class that takes in the root folder, a name, and deletes the name from a subfolder contained in a linked list.

public  class Delete {

    public static void delete_(String name, folder root)
    {
        for (folder s : root.folderlist) {
           delete_i(name, s);
        }
    }

    public static void delete_i(String name, folder check)
    {   
        if(check.name.equals(name))
        {
            int count = 0;
            System.out.println("Found folder! Deleting...");
            for(folder s : check.parent.folderlist)
            {
                if(s.name.contains(name))
                {
                    System.out.println("Found Parent folder of " + s.name + " which is " + s.parent.name + " Deleting from list...");
                    check.parent.folderlist.remove(count);
                    System.out.println("Folder successfully removed!");
                    break;
                }
                count += 1;
            }
        }
        for (folder l : check.folderlist) {

            delete_i(name, l);
        }

    }
}
user2796815
  • 465
  • 2
  • 11
  • 18

1 Answers1

2

It will change the object and delete from it.

quaertym
  • 3,917
  • 2
  • 29
  • 41