Zero-Based Indexing
Arrays in Java use zero-based indexing, meaning the first element is accessed with index 0, the second with index 1, and so on.
Java
/*package whatever //do not write package name here */ import java.io.*; class GFG { public static void main(String[] args) { int [] numbers = { 10 , 20 , 30 }; int firstElement = numbers[ 0 ]; // Accessing the first element // (index 0) System.out.println(firstElement); // Output: 10 } } |
10
25 Interesting Facts about Arrays in Java
Java arrays are the workhorses of many programs, offering a structured way to store and manipulate data. While arrays are a fundamental concept, there are intriguing facts that developers may not be aware of for Java Arrays. In this blog post, we’ll explore 25 interesting facts about arrays in Java, shedding light on their nuances and capabilities.
Table of Content
- 1. Zero-Based Indexing:
- 2. Fixed Size:
- 3. Primitive and Object Types:
- 4. Reference Variables:
- 5. Dynamic Initialization:
- 6. Array Copying:
- 7. Varargs and Arrays:
- 8. Arrays.asList():
- 9. Array Equality:
- 10. The Enhanced for Loop:
- 11. Cloneable Interface:
- 12. Arrays.deepToString():
- 13. Arrays.sort():
- 14. Parallel Array Sorting:
- 15. Jagged Arrays:
- 16. Memory Efficiency:
- 17. Array Initialization Shortcut:
- 18. Array Length Attribute:
- 19. ArrayDeque vs. Arrays:
- 20. Arrays.fill():
- 21. Garbage Collection:
- 22. Array Reflection:
- 23. Arrays and Generics:
- 24. Array Performance:
- 25. Arrays in Streams: