1

So I got this task to complete a method called "remove5List". This method has to remove every object with mod5==0 of a given LinkedList of type String.

My approach was that I use the mod operator, but it only works with Integer I guess. Now I got to a point where I don't know how to continue.

This is my first post here and I'm a total beginner, so correct me if I did something wrong.

//edit: The list is filled with numbers


static void remove5List(List<String> list)
    {
        ListIterator<String> iter = list.listIterator();


        while(iter.hasNext()) {
            //here I would like to check if I can divide the obj by 5
        }
    }

lew-kas
  • 41
  • 1
  • 8

1 Answers1

1

Please keep integers as integers

static void remove5List(List<String> list) {
            ListIterator<String> iter = list.listIterator();

            while (iter.hasNext()) {
                boolean mod = false;
                try {
                    int number = Integer.parseInt(iter.next());
                    if (number % 5 == 0) {
                        mod = true;
                    }
                } catch (Exception e) {
                }
    //if mod == true ,you can divide the obj by 5
            }
        }
RAJKUMAR NAGARETHINAM
  • 1,408
  • 1
  • 15
  • 26