I need to write a generic class pair which has two type


I need to write a generic class Pair which has two type parameters F and S (first and second) each representing the first and second elements of the pair. Add get and set elements so that the values of the pair can be changed.

This is an example of the code of the test class that calls for the pair class.

public class PairTest

{

public static void main( String args[] )

{

// create pair of integer and string

Pair< Integer, String > numberPair =

new Pair< Integer, String >( 1, "one" );

// display original numberPair

System.out.printf( "Original pair: < %d, %s >n",

numberPair.getFirst(), numberPair.getSecond() );

// modify pair

numberPair.setFirst( 2 );

numberPair.setSecond( "Second" );

// display modified numberPair

System.out.printf( "Modified pair: < %d, %s >n",

numberPair.getFirst(), numberPair.getSecond() );

} // end method main

} // end class PairTest

Solution Preview :

Prepared by a verified Expert
JAVA Programming: I need to write a generic class pair which has two type
Reference No:- TGS01250302

Now Priced at $20 (50% Discount)

Recommended (90%)

Rated (4.3/5)