Menu

Post image 1
Post image 2
1 / 2
0

Arrays and strings in Java — what they are and why they matter

DEV Community·Sahithi Reddy Gunupati·about 1 month ago
#grk3SVNB
#computerscience#java#dsa#arrays#array#string
Reading 0:00
15s threshold

When I started learning DSA, arrays were the first topic I encountered — and honestly, they seemed too simple to matter. Then I saw them show up in almost every interview problem I practiced. Turns out, understanding arrays and strings well is not optional. In this post, I'll walk you through what arrays and strings are, how they work in Java, and why they're foundational to everything else in DSA. What is an array? An array is a collection of elements stored in contiguous memory locations . Think of it like a row of lockers — each locker has a number (index), and you can jump to any locker directly without opening the ones before it. // Declaring and initializing an array in Java int [] numbers = { 10 , 20 , 30 , 40 , 50 }; // Accessing an element — O(1) time System . out . println ( numbers [ 2 ]); // Output: 30 // Length of the array System . out . println ( numbers . length ); // Output: 5 Enter fullscreen mode Exit fullscreen mode 💡 Indexing starts at 0 in Java.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More