This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
Beginner java programmer. I need to get the string length of a string array: This generated an error: int astrArrayLength = astrArray.length(); //get string length for (int i = 0; i < astrArrayLength; i++)
This got rid of the error: int astrArrayLength = astrArray.length; //get string length for (int i = 0; i < astrArrayLength; i++) Is length relaced with length()? Thank you.
Is length relaced with length()? No, I doubt that the compiler does anything special behind the scenes. Just think of any array in Java as an Object that has a length attribute. It's just one of those little quirks that you have to remember: arrays have a length attribute while String has a length() method. Go figure.
array.length will return the length of an array. string.length() is a method that returns the length of a string. Every array inherently knows its own length. It's a property of an array and can be shown with the array.length . I know it's a bit confusing, but just remember that's how it is.