#100DaysOfCodeChallenge

:computer: Day 71 of hashtag#100DaysOfCode – Arrays in Java with a Real-World Twist :rocket:

Today, I will discuss the classic yet powerful data structure: arrays in Java. But instead of just printing numbers, let’s do something a bit more interesting.

:brain: Quick Recap: What’s an Array?
An array is a fixed-size, indexed data structure that holds elements of the same type. It’s fast, predictable, and memory-efficient — making it a go-to tool in low-level operations and algorithm-heavy scenarios.

:sparkles: Real-World Use Case: Detecting Duplicate Votes in a Poll
Say we’re building a small voting system for a student council election. Each student can vote once, but what if someone tries to vote twice?
We’ll simulate a system that flags duplicate voter IDs using a simple array approach.

:pushpin: Step 1: Simulate Voter IDs
java
CopyEdit
int voterIds = {102, 205, 102, 310, 412, 205}; // Duplicate IDs: 102 and 205

:mag: Step 2: Detect Duplicates Using Nested Loops
java
CopyEdit
for (int i = 0; i < voterIds.length; i++) {
for (int j = i + 1; j < voterIds.length; j++) {
if (voterIds[i] == voterIds[j]) {
System.out.println("Duplicate vote detected from ID: " + voterIds[i]);
}
}
}
:jigsaw: Output:
csharp
CopyEdit
Duplicate vote detected from ID: 102
Duplicate vote detected from ID: 205
This is a brute-force approach (O(n²) time), but it’s a great demonstration of how arrays can power logic in real-world-like systems — even before you move into fancy data structures.

:bulb: Why Arrays Still Matter
Despite being “basic,” arrays are the foundation for:
Efficient memory handling
Fixed-size buffers
Algorithm challenges (sorting, searching, etc.)
Under-the-hood operations in Java collections like ArrayList