count item from arraylist by category
posted 9 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
hi i need help with my program , i want to count item from arraylist by category , but the category have duplicate item and the duplicate include count.
this my data
this my code
thanks before;
this my data
this my code
thanks before;
posted 9 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Can you post the program's current output and add some comments saying what is wrong with it. Also show what the correct output is.
A Map could be a better place to save the item counts. It would provide direct access and not require a search loop.
A Map could be a better place to save the item counts. It would provide direct access and not require a search loop.
daniel law
Greenhorn
Posts: 9
posted 9 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
thanks for respond norm
now output be like this
and the correct ouput should count category each transaction , the duplicate should not include count
like pembalut at transaction 8 , that should count 1 because at same transaction
now output be like this
and the correct ouput should count category each transaction , the duplicate should not include count
like pembalut at transaction 8 , that should count 1 because at same transaction
Norm Radder
Rancher
Posts: 5146
38
posted 9 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Did you look at using a Map so that there would not need to be a search loop?
Can you post the current output with some comments saying what is wrong with it?
Note: Posting images makes it impossible to copy text from the posted output when making a response to your post.
Can you post the current output with some comments saying what is wrong with it?
Note: Posting images makes it impossible to copy text from the posted output when making a response to your post.
daniel law
Greenhorn
Posts: 9
posted 9 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
ohh correct norm , its for map
i make a apriori algrthm for MBA
hmm sory my english very bad ..
if with that example :
my program output be like this:
how i count the kategory without count the duplicate ?
i try hashtree but not work, i think my code wrong
i make a apriori algrthm for MBA
hmm sory my english very bad ..
if with that example :
my program output be like this:
how i count the kategory without count the duplicate ?
i try hashtree but not work, i think my code wrong
Norm Radder
Rancher
Posts: 5146
38
posted 9 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
You need to describe the rules for the input? Are the input records sorted by no(column 1) and kategory?
If so, the code can save the values of the last line processed and skip following lines with the same no and kategory.
If so, the code can save the values of the last line processed and skip following lines with the same no and kategory.
daniel law
Greenhorn
Posts: 9
posted 9 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
hmm i think ya norm
i already make it by item , if by item there is no same name item
but if by category it has same name category
i already make it by item , if by item there is no same name item
but if by category it has same name category

Norm Radder
Rancher
Posts: 5146
38
posted 9 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Are the records in list_transaksi sorted? Or are they randomly ordered?
The first post shows the records as sorted.
The first post shows the records as sorted.
daniel law
Greenhorn
Posts: 9
posted 9 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
thats not yet sorted norm because just get the each category item and count it
later in proses need to sorted
later in proses need to sorted
Norm Radder
Rancher
Posts: 5146
38
posted 9 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
If the input is not sorted, then the code needs to keep track of the no values associated with the kategory that has been counted.
Using a Map with the key being kategory and the value being a custom class object that contains the no value for that kategory and the running count.
Using a Map with the key being kategory and the value being a custom class object that contains the no value for that kategory and the running count.
daniel law
Greenhorn
Posts: 9
posted 9 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
hmm sory norm
you mean the input is in my database ?
if yes , database already sorted
hmm if i want remove the duplicate catagory in each row how norm ?
what shoud i use ? hashtree ?
hmm i think it should be like this for no duplicate ? right ?
you mean the input is in my database ?
if yes , database already sorted
hmm if i want remove the duplicate catagory in each row how norm ?
what shoud i use ? hashtree ?
hmm i think it should be like this for no duplicate ? right ?
Norm Radder
Rancher
Posts: 5146
38
posted 9 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I thought the input to the method was the List: list_transaksi. If it's contents is not sorted, then you could handle that with a Map and the class I described.
daniel law
Greenhorn
Posts: 9
posted 9 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
norm that the input, if i want sort it just use orderBY ?
norm can you give me some example using map ?
norm can you give me some example using map ?
Norm Radder
Rancher
Posts: 5146
38
posted 9 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I don't have any code samples. Do a Search on the internet or here on this forum for code samples.
For learning about Maps I suggest that you write a small, simple test program that uses a Map.
For example one that counts the occurrences of words in a String. For example: given "This and this and this or that and that". Use the String class's split() method to get the individual words adn then use a Map<String, Integer> to count the occurrences of the words. The word is the key and the count is the value.
For learning about Maps I suggest that you write a small, simple test program that uses a Map.
For example one that counts the occurrences of words in a String. For example: given "This and this and this or that and that". Use the String class's split() method to get the individual words adn then use a Map<String, Integer> to count the occurrences of the words. The word is the key and the count is the value.
daniel law
Greenhorn
Posts: 9
posted 9 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
thanks norm.
i will try
hmm.. norm if i skip count if the cateogry same when looping , so i dont need map right ?
i will try
hmm.. norm if i skip count if the cateogry same when looping , so i dont need map right ?
Norm Radder
Rancher
Posts: 5146
38
posted 9 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
The Map saves the code from having to search for a matching name. It directly accesses the count for updating.
daniel law
Greenhorn
Posts: 9
posted 9 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Thanks norm.
Hmm. Now i have a problem with join tabel L2 oo L2 to find C3 in apriori
Example in table L2
1. A,b
2. B,c
3. C,e
I want join it to 3item set
Abc ( a,b , a,c ,b,c)
Abe (a,b , a,e, b,e)
Bce (b,c , b e, c,e)
The logic check if ab,ac,bc doesnt have at L2 it not in C3
But i dont know to implemnen it
This the example
Hmm. Now i have a problem with join tabel L2 oo L2 to find C3 in apriori
Example in table L2
1. A,b
2. B,c
3. C,e
I want join it to 3item set
Abc ( a,b , a,c ,b,c)
Abe (a,b , a,e, b,e)
Bce (b,c , b e, c,e)
The logic check if ab,ac,bc doesnt have at L2 it not in C3
But i dont know to implemnen it
This the example
posted 9 years ago
OK, lets back up a bit.
You have a bunch of Items in a List, and you want to perform all sorts of operations on that List.
Now in Java, a List is an ordered set of objects which can include "duplicates" (as defined by the equals() method of the object being stored).
But there are also other forms of collection:
1. A Set - which is a set of distinct objects - ie, no "duplicates".
2. A Map - which is a set of "mappings" of distinct keys to a "value" (which is usually a single object, but doesn't have to be).
Now Sets have all sorts of methods to aid Boolean operations - like "inner" and "outer" joins, subsets, and even unions - but, as I said, they are constrained by the "distinct" requirement - ie, they cannot hold "duplicate" objects.
So it seems to me that you need to define exactly what you want in terms of a Java collection.
So, just for example (and has already been suggested): if you want to generate counts of Items with a particular category, you might do something like this:
HIH
Winston
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
daniel law wrote:Hmm. Now i have a problem with join tabel L2 oo L2 to find C3 in apriori
OK, lets back up a bit.
You have a bunch of Items in a List, and you want to perform all sorts of operations on that List.
Now in Java, a List is an ordered set of objects which can include "duplicates" (as defined by the equals() method of the object being stored).
But there are also other forms of collection:
1. A Set - which is a set of distinct objects - ie, no "duplicates".
2. A Map - which is a set of "mappings" of distinct keys to a "value" (which is usually a single object, but doesn't have to be).
Now Sets have all sorts of methods to aid Boolean operations - like "inner" and "outer" joins, subsets, and even unions - but, as I said, they are constrained by the "distinct" requirement - ie, they cannot hold "duplicate" objects.
So it seems to me that you need to define exactly what you want in terms of a Java collection.
So, just for example (and has already been suggested): if you want to generate counts of Items with a particular category, you might do something like this:
HIH
Winston
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
| Power corrupts. Absolute power xxxxxxxxxxxxxxxx is kinda neat. The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |











