Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7820369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:15:54+00:00 2026-06-02T07:15:54+00:00

I am working on my first program that utilizes a generic method. I thought

  • 0

I am working on my first program that utilizes a generic method. I thought I was doing it correctly by setting the parameter to selectionSort(T[] a) so the method could receive an array of any object.

public class SelectionSort {
protected int[] arrayOne = {1,2,3,4,5,6,7,8};
protected double[] arrayTwo = {1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0};
public static <T extends Comparable<T>> void selectionSort(T[] a)
{
for (int index =0; index < a.length; index++)
{
    int minElementIndex = index;
    T minElementValue = a[index];
    for (int i = index + 1; i < a.length; i++) 
    {
        if (a[i].compareTo(minElementValue) < 0)
        {
            minElementIndex = i;
            minElementValue = a[i];
        }
    }//end of inner for loop
    a[minElementIndex] = a[index];
    a[index] = minElementValue;
}//end of outer for loop
for(int indexb = 0; indexb<a.length; indexb++)
{
    System.out.printf("%d ", a[indexb]);
    if(indexb == a.length)
        System.out.println("");
}
}
public static void main(String[] args)
{
selectionSort(arrayOne);
selectionSort(arrayTwo);

}}//end of main and SelectionSort

Perhaps you can help me out. If so I would greatly appreciate it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T07:15:55+00:00Added an answer on June 2, 2026 at 7:15 am

    Generics cannot be used with primitive types like int or double, which are not objects or classes. You will have to use the boxed versions Integer[] and Double[].

    In particular, if you want to support accepting primitive int[] and double[] arrays, you will have to write the code twice. =( (I can think of one semi-workaround, but not without using external libraries…)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a program that uses two tables. The first table has
I don't understand why the first program in JSP is working, but the second
Working on a program in python to print out the first 1000 prime numbers
I'm working on a socket program and everything seems fine when compiling. First I
working on making a flash program that loads about 1000 jpegs and then plays
I'm working with a c++ program that uses multiple buffers and I'm getting a
I'm working on a program that's supposed to represent a graph. My issue is
I'm working on a Java program that needs to send an image (preferably in
I am working on a small perl program that will open a site and
I'm working on a program that takes a redirected file as input. For example,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.