Java - how to get size of array

4 points
Created by:

In java every array has property .length not a method .length() or .size().


int[] intArray = new int[3];
int length = intArray.length; // 3

int[] intArray = {1, 2, 3};
int length = intArray.length; // 3

String[] stringArray = new String[3];
int length = stringArray.length; // 3

String[] stringArray = {"A", "B", "C"};
int length = stringArray.length; // 3


Hey 👋
Would you like to know what we do?
  • Dirask is a friendly IT community for learners, professionals and hobbyists to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.