Skip to content

Commit eb48782

Browse files
committed
feat: Iterate over custom Tuple array using descriptive reference variable
🧠 Logic: - Defined a `Tuple` class with two string fields: `first` and `second`. - Created an array of `Tuple` instances to simulate key-value data. - Used an enhanced for-loop with a descriptive reference variable `ReferencesToStoreValues` to access each tuple. - Printed each tuple in the format `first: second`, demonstrating tuple-like behavior using objects. Signed-off-by: Somesh diwan <[email protected]>
1 parent 07f6b02 commit eb48782

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

Section8LoopAB/Loop 2.O/src/ForLoopTuple.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
//tuples can be simulated using classes or Pair from external libraries (e.g., Apache Commons or JavaFX).
2-
//Here is an example using a custom tuple class:
1+
/*
2+
Tuples can be simulated using classes or Pair from external libraries
3+
(e.g., Apache Commons or JavaFX).
4+
5+
Here is an example using a custom tuple class:
6+
*/
37

48
class Tuple {
59
String first;
@@ -20,8 +24,8 @@ public static void main(String[] args) {
2024
};
2125

2226
// Iterating through the tuple array
23-
for (Tuple tuple : tuples) {
24-
System.out.println(tuple.first + ": " + tuple.second);
27+
for (Tuple ReferencesToStoreValues : tuples) {
28+
System.out.println(ReferencesToStoreValues.first + ": " + ReferencesToStoreValues.second);
2529
}
2630
}
27-
}
31+
}

0 commit comments

Comments
 (0)