Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Array List question

Featured Replies

I'm trying to remove a string from an array list but I'm getting an exception. I forgot with one it was. I looked it up and they said I need to iterate it from the array list. But it doesn't seem like its what I want to do with it. Any suggestions?

Are you modifying it from another thread? ArrayList is not thread safe, but you can set it as so by doing:

ArrayList<String> exmaple = (ArrayList<String>) Collections.synchronizedList(new ArrayList<String>());
  • Author

i don't know about threads too much. That's will be the next thing ill learn. But i'm as modify the arraylist. ill try that out later. Ill elt you know how it goes

are you getting a ConcurrentModificationException?

 

if so what Swizzbeat suggested will work although I wouldn't recommend using concurrent collections as they can be slower

 

 

you're probably getting that error because you're trying to do something like this

 

for(Element e : list) {
    if(e == null) {
        continue;
    }
 
    e.function();
    list.remove(e); // <- will throw a ConcurrentModificationException!!
}

you cant modify a list that isnt concurrent while doing this type of loop. use a raw iterator instead like so

 

for(Iterator<Element> iterator = list.iterator(); iterator.hasNext();) {
     Element e = iterator.next();
 
     if(e == null) {
         continue;
     }
 
     e.function();
     iterator.remove(); // <- does the same thing but no exception will be thrown!
}

or like I stated before, you can use a CopyOnWriteArrayList or what the dude above suggested

are you getting a ConcurrentModificationException?

 

if so what Swizzbeat suggested will work although I wouldn't recommend using concurrent collections as they can be slower

 

 

you're probably getting that error because you're trying to do something like this

for(Element e : list) {
    if(e == null) {
        continue;
    }
 
    e.function();
    list.remove(e); // <- will throw a ConcurrentModificationException!!
}

you cant modify a list that isnt concurrent while doing this type of loop. use a raw iterator instead like so

for(Iterator<Element> iterator = list.iterator(); iterator.hasNext();) {
     Element e = iterator.next();
 
     if(e == null) {
         continue;
     }
 
     e.function();
     iterator.remove(); // <- does the same thing but no exception will be thrown!
}

or like I stated before, you can use a CopyOnWriteArrayList or what the dude above suggested

I have a hunch this is what he's trying to do.

Guest
This topic is now closed to further replies.

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.