Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Output array I don't know what it is?

I have this code and when I run it I get this: [I@2c7b84de.

Can someone explain to me why I get that?

public class EJer22 {
    public static void main(String[] args){
        int[] numeros = { 50, 21, 6, 97, 18 };
        System.out.println(numeros);

    }
    public static int[] pruebas (int[] P){
        int[] S = new int[P.length];
        if(P.length < 10){
            System.out.println("Hay mas de 10 numeros");
        } else {
            for(int i = 0; i < P.length; i++){
                //S = P[i];
                if(10 >= P[i]){
                    S[i] = -1;
                    
                }else{
                    S[i] = P[i];
                }
            }
        }
        return S;
    }
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

numeros is an int array, which does not automatically serialise to a String. You are seeing the object reference value, rather than the contents.

If you convert it to a List, you will see the individual elements as the toString() method of List will do this for you

public static void main(String[] args){
    List<Integer> numeros = Arrays.asList(50, 21, 6, 97, 18 );
    System.out.println(numeros);
}

The pruebas method is never called but I guess that is not relevant to the question you’ve asked?

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading