This might be quite an obvious question but I haven't done Java for ages and I am trying to get back into it now. I have an ArrayList of type Double and I want to remove an item from the ArrayList so I use double l = f.remove(t); However it keeps telling me that f.remove(t) is a double not a boolean. Any idea what I am doing wrong? Key bits of code are below.
Thanks
[code]
public class Main {
public static void main(String[] args) {
double p = 5
ArrayList<Double> f = new ArrayList<Double>();
for (int i = 0; i < p; i++)
{
f.add(20);
}
remove(f);
}
private static void remove(ArrayList<Double> f) {
Random RandNo = new Random();
double t = RandNo.nextDouble();
double l = f.remove(t);
}
}[/code]
maybe f.remove(t); returns a bool (false if remove failed, otherwise true)
Ah I thought it removed the value that was removed rather than whether the object removed was successful. Guessing I need to use f.get(t);?
I wouldn't know, never used arraylists.
Because t is the value you want to remove it only returns a boolean, if you delete by index it returns the Double it removed.
You don't need to assign the f.remove(t) to anything, just invoke the method on it's own line.
You're basically storing true/false of whether it was able to do so.
Sorry, you need to Log In to post a reply to this thread.