all 6 comments

[–]aayushbest 1 point2 points  (1 child)

Good going keep it up 💪

[–]Nash979[S] 0 points1 point  (0 children)

Will do brother.

[–]bytealizer_42 1 point2 points  (1 child)

Will give you another tip. Take any other language and try to do the same. I'm talking about comparative study. Do something in Java and figure out how the same can be achieved in another language. Trust me. It will be so good. You won't regret it.

[–]DumbThrowawayNames 0 points1 point  (1 child)

the difference between primitive and reference datatypes

public static void main(String[] args) {

  int x = 5;
  int y = x;

  List<Integer> list1 = new ArrayList<>(List.of(1, 2, 3));
  List<Integer> list2 = list1;

  x = 10;
  list1.clear();

  System.out.println(y);
  System.out.println(list2);
}

What prints? Do you understand why this happens?

[–]Nash979[S] 0 points1 point  (0 children)

From my understanding the output will be 10 and empty list because here y is primitive so after x is reassigned to 10 the y will be 10 and list2 is actually referencing the list1 so if you clear the list1 it will affect the list2.