Method .size() vs property .length in Java

Is good to know the differences of the method size() and the property of vectors .lenght in Java. Is common seeing about this in introductory disciplines about programming in College exams questions for example.

The size method is disponible in the interface Collections according your definition:

Returns the number of elements in this collection. If this collection contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.
Returns:
the number of elements in this collection
int size();

The length property is not a method that return something but a property disponible in a Java Array(that is a Java Object), this property holds the quantity of objects in the vector.

Remembering that a Java Array have fixed size, the variable name just point to a memory, to change this you need reallocate memory using the keyword new as the final example bellow:

 public static void main(String[] args) {
    Integer[] numbersArray = {1, 2, 3};
    numbersArray = new Integer[] {1, 2, 3, 4, 5};
    List<Integer> numberList = new ArrayList<>();
    numberList.add(3);
    System.out.println("Size of array: "+  numbersArray.length); // Size of array: 5
    System.out.println("Size of list: "+ numberList.size());     // Size of list: 1
  }

The “Cannot find symbol” error when using MapStruct with Lombok

If you are having the problem “Cannot find symbol” with your Java project compilation because the compiler doesn’t recognize the methods calls of getters, setters, constructors, etc., but your IDE is still recognizing the methods normally, you probably forgot to configure your pom.xml or build.gradle for multiple annotation processors with the MapStruct library.

WARNING: If you’re using Intellij IDE check if the option “Enable annotation processing” is checked.

If your problem is more general, you can try the solutions provided in the Baeldung post.

Continue reading “The “Cannot find symbol” error when using MapStruct with Lombok”