r/learnprogramming • • Dec 03 '15

PSA: Don't use the Java standard library

Hey guys,

So I was working through an advent of code challenge, and it looks like apparently there are issues that can arise from the java standard library, in particular hashset. See here: https://www.reddit.com/r/adventofcode/comments/3v8roh/day_3_solutions/cxlfuvp?context=3

I'm a newbie so I thought others would want to know about this before trying to figure out why their programs aren't working. Write your own classes!

0 Upvotes

11 comments sorted by

View all comments

Show parent comment

5

u/zifyoip Dec 03 '15

I thought so at first, but someone else also said the same thing.

So what? I guarantee you it is not the fault of the Java standard library. The problem is in your code.

For example, are you absolutely certain that every character in directions is either 'v', '^', '<', or '>'? Are you sure there are no whitespace characters? Think about what happens when firstProblem is called with some character other than one of those four.

Have you even tested your program for simple inputs? The input > should produce the output 2, but your program produces the output 1.

I know for sure it's an error with HashSet

No, it is not a problem with HashSet. You are using it incorrectly, as /u/michael0x2a has pointed out. The error is your fault, not the standard library. Don't blame the tools.