Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
gorsamp19507yThis would be a great lesson for beginners since it shows loops, try-catch blocks, and arrays all in one nifty function
-
Maybe the problem statement was to calculate the length without using the length property. Just saying maybe there’s a reason.
-
What we are seeing here folks is what we are taught in an AP Computer Science A class.
-
bashlord4397y@abhishekb Still though, putting the try/catch inside the loop in stead of around it seems pretty inefficient, and if also looks pretty clumsy. Also, he could just have used an enhanced for loop with a counter like so:
‘for (Object o : array) i++;’
doing it that way prevents the exception from even being thrown. -
bashlord4397y@abhishekb
Oh and it’s probably cheating but just doing
‘return Arrays.asList(array).size()’
Would also get the job done without calling .length 🤓🙃 -
bashlord4397y@ArcaneEye It has a .length public attribute. And I agree, it's ridiculous, but @abhishekb pointed out that it might be because of a challenge to calculate the length without using .length, so I thought it would be fun to take a look and come up with some other, i.m.o. more elegant ways :) (which still should never be used in any serious projects of course 😅 )
-
@stevemk14ebr yes, because C is known for its exception usage and managed arrays, right?
@ArcaneEye it's Java. The highlighting theme is the IDEA Dark theme and .NET doesn't have ArrayIndexOutOfBoundsException and you'd probably use object instead of Object
Today on "How to do easy things the wrong way"...
undefined
if nobody reads the tags
do the tags even exist?