Explore BrainMass
Share

Explore BrainMass

    Java pair selection.

    This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

    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

    © BrainMass Inc. brainmass.com October 9, 2019, 10:45 pm ad1c9bdddf
    https://brainmass.com/computer-science/java/java-pair-selection-231132

    Solution Summary

    The expert examines a Java pair selection for two type parameters.

    $2.19