0

I really can't find any information about it that's why I'm asking here. I'm trying to figure out what is it type of Array if it has same name as a class... like:

public class ArrayOne {
    int SomeInt; 
    ArrayOne [] arr; 

    public ArrayOne(SomeInt){

       arr=new ArrayOne[1];
    }

}

Maybe someone know where can I read about it. Thanks a lot

1
  • It's an array of that type, in your case an array of ArrayOnes. What are you trying to do? Commented Aug 17, 2017 at 19:54

3 Answers 3

1

If you declare an array like this:

int[] myIntArray = new int[3];

you have an array of int (remember that int in java is not an object)

So if you write:

ArrayOne[] arr; 

You will have an array of object from class ArrayOne.

If you are still in doubt, you can check an array type like this:

Class ofArray = o.getClass().getComponentType();

take a look here : http://docs.oracle.com/javase/8/docs/api/java/lang/Class.html#getComponentType--

public Class getComponentType()

Returns the Class representing the component type of an array. If this class does not represent an array class this method returns null.

Sign up to request clarification or add additional context in comments.

2 Comments

How can I convert this Object`s Array to Int Array if I only need to Sort Integer Values of an Object for example with Bubble Sort? Because I can't use (ArrayOne[] arr) as a Parameter for example in Bubble Sort? Thank you again.
So this bubble sort algorithm, are you going to implement? If this is the case, you can pass the array o objects to the function. But you have to adapt the impllementation, to use something like arr.intValue . Or you can just create an array of int inside your ArrayOnr class, can't you?
0

That would be an array of that classes objects.

Comments

0

Your arr variable will be of Array type, which contains objects of ArrayOne type. If the question is around naming, then your array is named arr but not after the class which it is typed with.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.