📌 Arrays and Jagged Arrays in Java Hi Connections 👋 Understanding arrays is one of the first steps in learning Java properly. 🔹 What is an Array in Java? An array is a collection of elements of the same data type stored in continuous memory locations. ✔ Fixed size ✔ Same data type ✔ Access using index (starts from 0) 🔹 What is a 2D Array? >>A 2D array is like a table (rows and columns). >>Each row has the same number of columns. 🔹 What is a Jagged Array? >>A jagged array is a 2D array where each row can have a different number of columns. >>So the size of each row is different. 💡 Why use Jagged Arrays? Saves memory Useful when data is not uniform Common in real-world problems #Java #Arrays #JaggedArray #Programming #CodingJourney #LearnJava
Java Arrays and Jagged Arrays Explained
More Relevant Posts
-
Week 3 : Collection framework in java Day 11 : Collection framework : A Collection represent a group of object java collections provide classes and interfaces. Why need do we need Collections : We need collections for efficient storage and better manipulation of data in java. 1) Resize of an array. 2) Insert an element in between. 3) Delete and element in between. 4) Apply certain operations to change the array. Collection : The root interface for all the other collection types. 1) List : An ordered Collection that can contain duplicate elements . Example : arraylist, Linkedlist etc. 2) Set : A collection that cannot contains duplicate elements. Example : Hashset, Treeset. 3) Queue : A collection designed for holding elements prior to processing. 4) Deque : A double ended queue that allows insertion and removal at both ends. 5) Map : An interface that represents a collection of key value pairs . #java #backend #programming #collectionframeworks #learning #advancedjava EchoBrains
To view or add a comment, sign in
-
-
Today I focused on understanding the types of variables in Java and how their behavior changes depending on where they are declared. At first it looked simple, but while going through examples, I realized that the real difference is not the datatype — it is the scope, initialization, and memory behavior of the variable. Things that became clear: - Local variables exist only inside methods, blocks, or constructors and must be initialized before use - Their scope is limited to the method in which they are declared - Instance variables are declared inside a class but outside methods and are automatically initialized with default values by the compiler - These default values depend on datatype, such as 0 for numeric types, false for boolean, '\0' for char, and null for objects - Instance variables are accessible across all methods of the same class, showing how objects maintain state Seeing the object example made the concept clearer, an object holds its own copy of instance variables, which get real values only after initialization. The biggest realization from this topic was simple - Understanding Java is less about syntax and more about how memory, scope, and initialization actually work. Small concept, but an important foundation for everything ahead. #java #programming #learninginpublic #javabasics #codingjourney
To view or add a comment, sign in
-
While solving a DSA problem on LeetCode, I noticed the solution used StringBuilder instead of a normal String in Java. At first I thought — why not just use String? 🤔 While exploring this, I learned that every time we modify a String, Java creates a new object in memory. The old objects become unused, which are called garbage values and later cleaned by the garbage collector. A small doubt while solving one question helped me understand how memory actually works in Java 💡 #Java #DSA #LearningInPublic #Programming #LeetCode
To view or add a comment, sign in
-
🚀 Day 10 – How Arrays Really Work in Java Today I went beyond basic syntax and understood how arrays actually work internally in Java. 🔎 What I explored: ✔️ How arrays are stored in contiguous memory locations ✔️ How index-based access works (0-based indexing) ✔️ How array size is fixed after creation ✔️ How reference variables point to array objects in memory ✔️ Time complexity of accessing elements – O(1) Understanding the internal working of arrays helped me realize why they are fast for accessing elements but limited when it comes to resizing. This concept is very important before moving to advanced data structures like ArrayList, LinkedList, and more. 🙏 Special thanks to Aditya Tandon Sir for explaining the internal memory concept so clearly. #Day10 #Java #Arrays #DataStructures #LearningJourney #Programming #Coding #JavaDeveloper
To view or add a comment, sign in
-
-
Day 44 of #100DaysOfLeetCode 💻✅ Solved Very Simple #169. Majority Element problem in Java. Approach: • Sorted the given array using Arrays.sort() • Observed that the majority element appears more than n/2 times • After sorting, the majority element will always be present at index n/2 • Returned the element at nums[n/2] Performance: ✓ Runtime: 7 ms (Beats 42.86% submissions) ✓ Memory: 55.96 MB (Beats 16.21% submissions) Key Learning: ✓ Understood how sorting can help identify the majority element ✓ Learned the property that the majority element always occupies the middle position after sorting ✓ Practiced array manipulation and problem solving in Java Learning one problem every single day 🚀 #Java #LeetCode #DSA #Arrays #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Understanding the final Keyword in Java In Java, the final keyword is used to restrict modification. Once something is declared as final, it cannot be changed in the future. 🔹 Final Variable A variable declared as final becomes a constant. Its value cannot be modified after initialization. 🔹 Final Method A method declared as final cannot be overridden by subclasses. 🔹 Final Class A class declared as final cannot be extended (inherited by another class). 💡 The final keyword helps improve security, immutability, and code reliability in Java applications. #Java #Programming #JavaDeveloper #Coding #OOP #LearningJava #ComputerScience
To view or add a comment, sign in
-
-
A variable is a container used to store data that can change during the execution of a program. In Java, every variable must have a data type, which defines what kind of data it can store (like int, double, String, etc.). 🔸 Types of Variables in Java 1️⃣ Local Variable A local variable is declared inside a method, constructor, or block. ✔️ Scope: Accessible only within that method/block ✔️ Lifetime: Exists only while the method is executing ✔️ Must be initialized before use 2️⃣ Instance Variable An instance variable is declared inside a class but outside any method. ✔️ Scope: Accessible throughout the class ✔️ Lifetime: Exists as long as the object exists ✔️ Each object has its own copy 🔎 Quick Difference 🔹 Local Variable → Belongs to a method 🔹 Instance Variable → Belongs to an object #Java #Programming #SoftwareDevelopment #Coding #LearningJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day - 30 : Deque in java 1) Allows insertion and removal of elements from both ends. 2) Versatile than regular queue and stack because they support all operations of both. ● Insertion methods : 1) addFirst : Inserts the specified elements at the front. 2) addLast : Inserts the specified element at the last. 3) offerFirst : Inserts the specified element at the front if possible. 4) offerLast : Inserts the specified element at the end if possible. ● Removal methods : 1) removeFirst () : Retrieves and removes the first element. 2) removeLast () : Retrieves and removes the last element. 3) pollfirst () : Retrieves and removes the first element or returns null if empty. 4) pollLast() : Retrieves and removes the last element or returns null if empty. #Java #CoreJava #coding #programming #learning #Deque
To view or add a comment, sign in
-
-
📚 Today I Learned: Arrays in Java Today I explored the concept of Arrays in Java. Arrays allow us to store multiple values of the same data type in a single variable, which makes data management easier and more organized. 🔹 Arrays store multiple elements in one variable 🔹 Each element is accessed using an index 🔹 Index values start from 0 in Java 🔹 All elements in an array must have the same data type Example: int[] marks = {80, 75, 90}; Learning arrays helped me understand how to efficiently handle collections of data in programming. Looking forward to learning more about data structures and improving my coding skills. 🚀 #Java #JavaProgramming #Arrays #CodingJourney #LearnJava #ProgrammingBasics #SoftwareDevelopment #DeveloperJourney #CodingPractice #TechLearning #FutureDeveloper #CodeNewbie #100DaysOfCode #TechSkills #ProgrammingLife
To view or add a comment, sign in
-
-
Many developers ask: Why do Java Collections not support primitive data types? The reason is that Java Collections work with objects, not primitives. To handle primitive values, Java uses Wrapper Classes like Integer, Double, and Character. Example: int → Integer double → Double char → Character This process is called Autoboxing and Unboxing. Understanding such small concepts can make a big difference in mastering Java. 🚀 #CoreJava #JavaTips #Programming #JavaDeveloper
To view or add a comment, sign in
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development
They save memory, but a 2D array can be internally implemented as a 1D array with some maths-based indexing whereas a jagged array will almost certainly need to be implemented with different allocations for each row. So there is a trade-off in terms of things like cache coherency. (Disclaimer: I know nothing about Java and I'm talking from a C and C++ perspective, but I presume the same applies)