Eric Matthew

Greenhorn
+ Follow
since May 03, 2015
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Eric Matthew

What small thing did you over look or perhaps didn't click-in/notice right away for you that caused so much frustration?

Awhile back ago, I had a difficult time parsing/splitting a CSV(Comma Seperated Values) file that had fields with commas in them "Plumbing & Cleaning, Inc." and "$1,999.00". So I read up on Regular Expressions hoping to get some voodoo magic working for a few days.
Then I realized I could just excel to select all the Strings and Integers, find & replace all the "," with "". Bam, all extra commas gone. Don't know how this slipped my mind.

How about yourself? What can we learn from your pain and suffering?
8 years ago
Thanks for the response Henry, I thought about going through that route - just storing them as Integers/ints than when the values (for the Integers) are called, then checking to see if the value is greater than or less the known boundaries for zip codes. Seems a lot better than storing a bunch numerical types as Strings.
8 years ago
I'm making a program that is storing over 40,000 different zip codes and many of these zip codes have leading zeroes. I know I can use String to get around that but I learned that it's best to avoid using Strings for numerical types of data so I'm trying to avoid that route. Or is it best for this particular case to use Strings as opposed to the numerical types? Plus, I just read "Strings are bad" https://coderanch.com/how-to/java/StringsAreBad so that's why I'm mainly avoiding wanting to use Strings as well.

Oh, just to clarify. I understand that 00555 is the same as 555 and such.

Additional info if it helps: The zip codes are stored in txt file that are read from a scanner object.

Here's the code FWIW



And oh, I know I can make my code a bit more clearer by removing unneeded variables but I left everything in place til I can get some guidance how to proceed.
8 years ago
This isn't homework or anything school related, just a small part of a personal project of mine. My main personal project searches given URLs and other text files looking for specific key words, keeps a count on how many times it was found and stores the values in a map object. This, soon to be a method, took longer than I expected or maybe I'm just really tired. Open to any improvements or criticism.

My intentions with this code is just to simply return a String, a sentence in which the specific key word was found, and print it out or perhaps store it in a List and print it later..
8 years ago
If there is, I can't find it. Any help appreciated. Thanks.
I have a method that test whether an array's elements are all equal. The method contains a for loop to test, and if they are equal, increments a counter. But for some reason, my counter is increasing more than the times I am even testing it.



This is part of the method. There is more to it but I feel as though I'm forgetting something more trivial.
8 years ago
Basically I just want the keys to increment different int counter variables each time the keys are retrieved.

Example:



Not sure if I'm on the right track. A bit lost here. Thanks CodeRanch!
8 years ago

Bear Bibeault wrote:

Eric Matthew wrote:I understand you may want to make a variable of an interface type


Then you understand why the variable should be List and not ArrayList.

So I'm not sure what it is that you do not understand.



I think my confusion arises from tutorials and code examples that do it this way when the ArrayList they're making is only going to be used only for one purpose. If there's no intention to change it later, why not just make List<> to ArrayList<>. But I think I fully grok it. Thank you.
8 years ago
Example



why is List added before <Student> since ArrayList already implements the List interface by default. Just seems redundant. Why not make it like this:



I understand you may want to make a variable of an interface type but I don't understand why classes that already implement an interface in the Java API do this. Maybe I'm thinking of this the wrong way. Any clarification of this would be appreciated. Thank you coderanch.

edit: Is it because if I decide later I want to change value of the variable( to linkedlist or vector) I wouldn't be able since it was declared it of type ArrayList<> instead of List<> ?
8 years ago
Thank you Piet and Ritchie for your replies and possible solutions. Despite how daunting it looks, I really enjoyed looking over them and look forward to learning more.

And thank you Robert for your comment, I don't know why I didn't see it that way before but now looking it that way makes it much more clearer in my head now.

I believe I found a solution that doesn't involve ArrayList, Collections, Streams or anything scary that I haven't learned yet. Just for and if loops.

Here is the code without any comments.



The code again but with comments.


Feel free to not hold back and critique any inefficiencies you notice or any adjustments that can be made.
8 years ago
Is there any way to do this without resorting to using ArrayList and Collections.shuffle? I'm just trying to figure out if it is possible using a series of loops and or booleans.

package prayitworks;



Main method below



Any help would be appreciated.Thank for taking the time to look over.
8 years ago
Thanks for the replies guys, really do appreciate it. I haven't exactly figured out the problem but I believe it stems from a not knowing a more intermediate topic regarding java, "ArrayList", that I'm not familiar with. ArrayList objects are dynamic which is what I was looking for as opposed to a static number of elements.
8 years ago