-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Driver class and Test Generic Pair.
- Loading branch information
1 parent
ae5a74c
commit 1bef1b2
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
JavaDsaWithTest/src/main/java/org/practice/dsa/generics/pair/PairTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.practice.dsa.generics.pair; | ||
|
||
public class PairTest { | ||
public static void main(String[] args) { | ||
|
||
// Pair for name and age, i.e. of type String and Integer | ||
Pair<String, Integer> agePair = new Pair<>("Vishwajeet",24); | ||
System.out.println("Name and Age: "+agePair); | ||
System.out.println("Name is: "+agePair.getKey()); | ||
System.out.println("Age is: "+agePair.getValue()+"\n"); | ||
|
||
// Pair for Double and Boolean | ||
Pair<Double, Boolean> coordinates = new Pair<>(323.2, true); | ||
System.out.println("The coordinates are: "+coordinates); | ||
System.out.println("Get the coordinates: "+coordinates.getKey()); | ||
System.out.println("Get Validity: "+coordinates.getValue()+"\n"); | ||
|
||
// Pair for String and String | ||
Pair<String, String> countryPair = new Pair<>("India", "New Delhi"); | ||
System.out.println("The country and capital: "+countryPair); | ||
System.out.println("The capital is: "+countryPair.getValue()); | ||
|
||
// set new value to pair | ||
System.out.println(); | ||
agePair.setValue(25); | ||
System.out.println("Age in year 2025 is: "+agePair.getValue()); | ||
} | ||
} |