Ad
  • Custom User Avatar

    Note that in the situation where your array is of length 1 then you will get an "Array Index Out Of Bounds Exception".

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Single exit strategy is a controversial discussed dogma. For instance the Object.equals() method uses multiple return statements. Just have a look at the source code. Perhaps you shall advise Oracle that you think they're using bad pracice and improve the Java code base with a better solution. Your approach may be good for these concrete kata, but it is indeed not a general valid way, to solve all problems of that type, as you can see.

    Hence, my question was not about linking connections to anything, but wanting to know, how you would solve problems of that kind in general, if something like IntStream was not accessible. Since clairvoyance does not exist, nobody can elaborate how your solution would look like. This is just a red herring argument. I would be grateful, if you could take two minutes to show a good way that works even for cases when Streams don't work, with a single exit point. And of course, without a break in the loop, because it violates your choosen strategy.

  • Custom User Avatar

    If it was a replay to my comment can elaborate on your thought. I'm not sure that I've understood correctly what you are trying to convey.
    What is the connection between import statements and best coding practices?

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Apart from the weird formatting multiple return statement is not a best practice.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    the java version has been corrected.

  • Custom User Avatar

    Yes, there is something wrong with the performance of your solution. It's too slow. Your current apporoach is never going to work.

  • Custom User Avatar

    Could anyone tell me what's wrong with my solution, cause i can't find any mistake with it.

    public static Object[] sortArray(Object names){
    	if(names.getClass().isArray()){
    		int length = Array.getLength(names);
    		Object[] array = new Object[length];       
    		for (int i = 0; i < length; i++) {
    			array[i] = (Array.get(names, i));
    		}
    		if(length > 1){Arrays.sort(array);}
    		return array;			
    	}
    	else{
    		return new Object[]{names};
    	}	
    }
    
  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution