java


Equals two Variables from two Arraylists


I want to create simple cash register.
I already have two ArrayLists, one is my "DataBase" second is used to store purchased products. How can I equal ID from DataBase with ID from input product? In the ArrayLists I have variable id, name and price.
Arraylists<Products> products = new ArrayLists<Products>(); <- Database
ArrayLists<purchased> purchased = new ArrayLists<purchased>() <-List of purchased products
I passed to the function object Product.
For such case it is better to use Maps rather than Lists. IDs will be keys and objects will be values.
With Lists you have to loop through them and compare ID,, each time you need to find a match. But with Maps you just use dbmap.get(ID) or productMap.get(ID) and you have your object instantly.

Related Links

Bad practice or not when running code every 5 seconds?
How can I add two variables in a java subclass to pass as one variable to the superclass?
88byte output from AES encryption
WCF call Java SOAP service - namespace issue
WebSockets in Java EE?
program stalls immediately after beforeclass with log4j and springframework
Java Invalid maximum heap size
Changing EditText style each words contained within
JSoup check if <HTML>,<HEAD> and <BODY> tags are present
How to set a variable equal to null in debug mode within eclipse
Resource IDs and Devices
clear text password issues with Jenkins m2 release plugin or maven release plugin
Cannot save text from Edittext
How to determine which driver to use for JDBC
Want to throw exception when encounter special UTF-8 characters in an XML file
How to remotely build and run applications?

Categories

HOME
yii2
activiti
pycharm
kde
path-finding
appx
alfresco
youtube-dl
rubygems
jgroups
cross-validation
amazon-cloudformation
row
resize
collectd
dtrace
opencover
ehcache
css-animations
excel-2007
firebase-crash-reporting
numerical-methods
facet
filezilla
rst2pdf
elasticsearch-ruby
elasticsearch-net
replaceall
javascriptcore
semantic-versioning
gtrendsr
calibre
catch-all
framemaker
amazon-kinesis-kpl
catalog
host
lto
impersonation
graphenedb
unoconv
gulp-sourcemaps
powershell-dsc
jvm-languages
android-mediaprojection
node-sass
sencha-touch-2.3
thin
convertapi
angular2-meteor
hibernate-tools
qsslsocket
worker-thread
android-cursor
gcsfuse
eventkit
deadbolt-2
libpng
dstu2-fhir
markojs
wapiti
tcpserver
rtbkit
spim
qtableview
pundit
security-testing
ionic
method-parameters
graph-drawing
sortedlist
composite
key-management
javax.mail
device-manager
eol
sgen
htmlcleaner
hippomocks
mbr
jmapviewer
mylyn
ember-app-kit
dmoz
trusted
newtonscript
hgsubversion
gnu-prolog
data-loss
appendto
krl
disclosure
oncheckedchanged
locate
mongomapper
sef
exchange-server-2003
commodore

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App