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

  • SEARCH
  • Home
  • 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 763987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T16:38:55+00:00 2026-05-14T16:38:55+00:00

Okay, here is what I want to do: I want to implement a crossover

  • 0

Okay, here is what I want to do:

I want to implement a crossover method for arrays.

It is supposed to take 2 arrays of same size and return two new arrays that are a kind of mix of the two input arrays.
as in [a,a,a,a] [b,b,b,b] ——> [a,a,b,b] [b,b,a,a].

Now I wonder what would be the suggested way to do that in Java, since I cannot return more than one value.

My ideas are:
– returning a Collection(or array) containing both new arrays.

I dont really like that one because it think would result in a harder to understand code.
– avoiding the need to return two results by calling the method for each case but only getting one of the results each time.

I dont like that one either, because there would be no natural order about which solution should be returned. This would need to be specified, though resulting in harder to understand code.

Plus, this will work only for this basic case, but I will want to shuffle the array before the crossover and reverse that afterwards. I cannot do the shuffling isolated from the crossover since I wont want to actually do the operation, instead I want to use the information about the permutation while doing the crossover, which will be a more efficient way I think.

My question is not about the algorithm itself, but about the way to put in in a method(concerning input and output) in Java

  • 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-05-14T16:38:56+00:00Added an answer on May 14, 2026 at 4:38 pm

    Following a suggestion from Bruce Eckel’s book Thinking in Java, in my Java projects I frequently include some utility classes for wrapping groups of two or three objects. They are trivial and handy, specially for methods that must return several objects. For example:

    public class Pair<TA,TB> {
        public final TA a;
        public final TB b;
    
        /**
         * factory method
         */
        public static <TA,TB> Pair<TA,TB> createPair(TA a,TB b ){
            return new Pair<TA,TB>(a,b);
        }
    
        /**
         * private constructor - use instead factory method 
         */
        private Pair(final TA a, final TB b) {
                this.a = a;
                this.b = b; 
        }
    
        public String toString() {  
            return "(" + a + ", " + b + ")";
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, I think I'm just making a stupid mistake here, but I want to
Okay here is what I'm trying to do: I have a model object that
Okay, Here's a breakdown of what's up: <? $foo = new Imagick(); ?> works
Okay, this code gives me exactly what I want but it seems that it
Okay here is what I'm, trying to do I want to escape the period
Okay so here my issue, I have a list of items that when a
Okay big brains here's something that's more of a challenge than a requirement. I
I want to implement a program that shows some chars moving randomly on console,
Okay here's the situation. Net 4 WPF NO Silverlight. I have several Views that
Okay, I haven't posted much here before, but I'm struggling with something that I

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.