d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Arraylist
Add Reply New Topic New Poll
Member
Posts: 8,250
Joined: May 10 2012
Gold: 0.00
Mar 8 2015 06:45pm
Just have a few questions involving them in code.
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Mar 8 2015 06:46pm
Quote (axid3nt @ Mar 8 2015 08:45pm)
Just have a few questions involving them in code.


would help if you posted your questions and any code snippets you're confused about.
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Mar 8 2015 07:00pm
Quote (carteblanche @ Mar 8 2015 08:46pm)
would help if you posted your questions and any code snippets you're confused about.


But that's too logical.
Member
Posts: 8,250
Joined: May 10 2012
Gold: 0.00
Mar 8 2015 07:25pm
Quote (carteblanche @ Mar 8 2015 08:46pm)
would help if you posted your questions and any code snippets you're confused about.


I wasn't sure if anyone was on. I usually talk on messenger.

I was concerned about setting the boolean value of a string from false to true.

What methods are most efficient?

I am making a library with books/cds/games on loan and was seeking to change statuses like "onLoan" from F to T
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Mar 8 2015 07:30pm
Quote (axid3nt @ Mar 8 2015 09:25pm)
I wasn't sure if anyone was on. I usually talk on messenger.

I was concerned about setting the boolean value of a string from false to true.

What methods are most efficient?

I am making a library with books/cds/games on loan and was seeking to change statuses like "onLoan" from F to T


not sure what you're talking about when you say "boolean value of a string". do you mean you're using some kind of Map<String, Boolean>? or you have an object with a boolean onLoan instance variable (and getter/setter)?

myarraylist.get(0).setOnLoan(true);

This post was edited by carteblanche on Mar 8 2015 07:30pm
Member
Posts: 8,250
Joined: May 10 2012
Gold: 0.00
Mar 8 2015 07:32pm
Yeah, the getter/setter.

I need to have a constructor to set the value, but I also need to have the program start without the value being false.

Seems like a logical concept, but kind of kicking at rocks figuring it out.

This post was edited by axid3nt on Mar 8 2015 07:33pm
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Mar 8 2015 07:57pm
Quote (axid3nt @ Mar 8 2015 09:32pm)
Yeah, the getter/setter.

I need to have a constructor to set the value, but I also need to have the program start without the value being false.

Seems like a logical concept, but kind of kicking at rocks figuring it out.


you mean starts neither false nor true? look into alternatives to boolean, eg use a flag (int, string, enum, etc). alternatively you can use Boolean wrapper class, but i'm not a fan of that as a means to use 3 states.

or if you mean start it as true, then make that your default value.

This post was edited by carteblanche on Mar 8 2015 07:59pm
Member
Posts: 8,250
Joined: May 10 2012
Gold: 0.00
Mar 8 2015 08:27pm
Quote (carteblanche @ Mar 8 2015 09:57pm)
you mean starts neither false nor true? look into alternatives to boolean, eg use a flag (int, string, enum, etc). alternatively you can use Boolean wrapper class, but i'm not a fan of that as a means to use 3 states.

or if you mean start it as true, then make that your default value.


Alright, I will keep trying different things until I am satisfied. Thanks for the suggestion.
Member
Posts: 5,167
Joined: Nov 23 2006
Gold: 11.01
Mar 9 2015 06:32am
Default the value to true for your object when you're reading them in from a file or manually entering them. Then set the value to false whenever one is checked out in your checkout() function or whatever.

First you'll have to find the object in your ArrayList when it's checked out, change it from true to false.

In your obj class you can have a function called

public void isCheckedout(){
setCheckout(false);
}

That way you're not accessing the mutator (set) method directly in your main class but you have access to a public isCheckout function so you'd just do Arraylist>object.isCheckedOut(); or something similar to that.
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll