Re: what am i doing wrong here?



Jeremy Watts wrote:
"Jeremy Watts" <jwatts1970@xxxxxxxxxxx> wrote in message news:eUioe.1480$jS3.477@xxxxxxxxxxxxxxxxxxxxxxx

"Andrew McDonagh" <news@xxxxxxxxxxxxxxxxxxxxx> wrote in message news:d7rte8$cda$1@xxxxxxxxxxxxxxxxxxxxxxxx

Jeremy Watts wrote:

Hi,

I've written a Java method that uses a list to return 5 three-dimensional arrays containing 'Big Decimal' entries. However I also want to return a single boolean type variable, but cant seem to get the program to do this.

My method basically goes :-

start method {

declare arrays and variables
List result = new ArrayList(5)
..
..
..
..
REST OF METHOD
..
..
..
result.add(first array)
result.add(second array)
etc
result.add(fifth array)

return (result)

end method }


This works fine for just the arrays, but if I attempt to add the line
'result.add(LDMexists)' , to return the boolean variable 'LDMexists' then I get the error message ' cannot resolve symbol - method add(boolean)'


I have declared the boolean type LDMexists, so I cant see what I'm doing wrong here - how do I get it to return the five arrays and the boolean variable LDMexists?

Thanks

the ArrayList only allows Object references to be added, where as 'boolean' (Note the lowercase B) is a primitive not an object.


you can change the code to...

result.add(Boolean.valueOf(LDMexists));

This adds a reference to the Boolean object (note the uppercase B) to the arraylist.

http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Boolean.html#valueOf(boolean)

HTH

Andrew

Hi Andrew,

Thanks for that, that seems to work. How would you then reference that variable though once the procedure has been called? I cant seem to get that bit to work now.

Thanks
Jeremy


managed to get that to work - it seems that the boolean value is returned as a string? so i needed to put quote marks around the 'true' or 'false' :)






nope, you have mere stringified the Boolean object.

Boolean fromTheList = (Boolean)result.get(index);

LDMexists = fromTheList.booleanValue();


http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Boolean.html#booleanValue()


.



Relevant Pages

  • Re: what am i doing wrong here?
    ... I've written a Java method that uses a list to return 5 three-dimensional arrays containing 'Big Decimal' entries. ... However I also want to return a single boolean type variable, but cant seem to get the program to do this. ... I have declared the boolean type LDMexists, so I cant see what I'm doing wrong here - how do I get it to return the five arrays and the boolean variable LDMexists? ...
    (comp.lang.java.programmer)
  • Re: what am i doing wrong here?
    ... I've written a Java method that uses a list to return 5 three-dimensional arrays containing 'Big Decimal' entries. ... However I also want to return a single boolean type variable, but cant seem to get the program to do this. ... I have declared the boolean type LDMexists, so I cant see what I'm doing wrong here - how do I get it to return the five arrays and the boolean variable LDMexists? ... This adds a reference to the Boolean object to the arraylist. ...
    (comp.lang.java.programmer)
  • Re: working with byte arrays
    ... faster than my current solution because the whole comparisson is done inside ... Thanks for the hint to check the size of the arrays, ... BAs Byte) As Boolean ... > same lower bound, then these can be simplified to these... ...
    (microsoft.public.vb.general.discussion)
  • Re: what am i doing wrong here?
    ... I've written a Java method that uses a list to return 5 three-dimensional arrays containing 'Big Decimal' entries. ... However I also want to return a single boolean type variable, but cant seem to get the program to do this. ... I have declared the boolean type LDMexists, so I cant see what I'm doing wrong here - how do I get it to return the five arrays and the boolean variable LDMexists? ...
    (comp.lang.java.programmer)
  • Re: what am i doing wrong here?
    ... I've written a Java method that uses a list to return 5 three-dimensional arrays containing 'Big Decimal' entries. ... However I also want to return a single boolean type variable, but cant seem to get the program to do this. ... I have declared the boolean type LDMexists, so I cant see what I'm doing wrong here - how do I get it to return the five arrays and the boolean variable LDMexists? ...
    (comp.lang.java.programmer)