Kat Rollo

Ranch Hand
+ Follow
since Jun 30, 2014
Kat likes ...
Eclipse IDE Java MySQL Database
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
2
Received in last 30 days
0
Total given
5
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Kat Rollo

The comments and sysouts were just for instructional purposes. They're not really meant to be there. It's also intended to be nearer the OP's original code:

2 years ago

Sample Execution:

Here's my solution with comments and sysouts so you see what's happening. It also works for unsorted lists and multiple occurrences of elements (duplicate, triplicate, and so on).

As a bonus (if you're not familiar with it yet), we're using a foreach-loop here. It's an enchanced for-loop that's great for traversing collections forward.
2 years ago

Joshua Harris wrote:

Kat Rollo wrote:


So for example, in an ArrayList of strings which contains cat, cat, dog, horse, zebra, zebra, the answer should be two.


For example if your list contains:
cat
cat
dog
dog
horse
zebra
zebra

The output is 3 because cat, dog, and zebra are duplicated?



Yes. No matter how many duplicates there are of a word, it should only increase the duplicate count by 1. It's counting how many words there are which have duplicates, not how many duplicates of a word there are.


Thanks for the clarification.

Karthick Pattabiraman and I have the same solution (though I didn't post mine). Here is how the algorithm went:

1) Get all unique elements from the List.
2) Check the occurrence of each unique element in the List.
3) If an element occurred more than once, increment your counter.

Since you seem to be studying Collections, you may want to read up on the Java Collections Framework and Collections API.

Goodluck!
2 years ago
I thought the solution was wrong. We have the same answer.
But I get what you're saying.
2 years ago
@Liutauras Vilda:
Why? Was his answer incorrect?
2 years ago


So for example, in an ArrayList of strings which contains cat, cat, dog, horse, zebra, zebra, the answer should be two.


For example if your list contains:
cat
cat
dog
dog
horse
zebra
zebra

The output is 3 because cat, dog, and zebra are duplicated?
2 years ago
When it comes to returning values, putting it in a variable improves readability if the return statement is too long or unwieldy.
2 years ago

Joshua Harris wrote:



Is this what you want?

Sample Execution:


Enter letter: b
Your index is: 1


It returned 1 because "banana" is the first String that starts with "b" in the List.
2 years ago
Hi guys,

What are the disadvantages of using an ORM like Hibernate? I do hope for an objective list of disadvantages, not an "ORM fanboy" list.
Sometimes, it feels like articles don't elaborate or minimize the disadvantages because the author likes the technology so much.

Thanks.
Hey thanks, I do agree it's a good investment.
The common lot of internet people are like that. Hahaha.
Some don't even know how to View Source code. OTL
3 years ago
doPost() is good for security because you don't want sensitive information being seen by the user in the URL box.
3 years ago
Honestly, I'm a bit scared to touch Hibernate. There seems to be a lot going on under the hood and it might be too powerful for someone just beginning JavaEE and frameworks.
I personally like managing my own SQL statements and closing my own resources.
But it seems there are a lot of job offers with Hibernate.
Thanks for your response. Is plain JDBC/SQL no longer used in the outside world?
For a school project, my group is planning to use Struts2 with plain JDBC/SQL for database. The database is expected to have around 1000 records (or less).
The Struts2 is pretty much set. However, is it a good choice to use plain JDBC/SQL or go with Hibernate instead?