How would you dynamically allocate memory to an array?



How would you dynamically allocate memory to an array?..

Answer / Mushahid

In Java, arrays are typically declared with a fixed size, but you can dynamically allocate memory for an array using the Array class. You can create a new array of a specified type and size like this: 'DataType[] arr = new DataType[size];'. For example, 'int[] intArray = new int[10];' creates an array of integers with 10 elements.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Core Java Interview Questions

How many bits is a float?

1 Answers  


Why is singleton class used?

1 Answers  


What is a line break?

1 Answers  


Can i have abstract class with no abstract methods?

22 Answers   CTS,


What does indexof mean?

1 Answers  


How do you define a variable?

1 Answers  


What is prefix of a string?

1 Answers  


What is the benefit of abstract class?

1 Answers  


What is function declaration?

1 Answers  


In the first round, there are 30 aptitude and 30 java questions. We are suppose to finish both the papers within 60 minutes. I cleared this round. Next was test for programming skills. In this section, Some 7 n's were asked. 1. What is the difference b/w sleep(1000) and wait(1000) 2. what is the diff b/w static block and static function? 3. Write a program to validate IP address using string tokenizer. 4. Write a program to create singleton class 5. write a function to reverse the string 6. Write a prog to print prime nos upto n. EX: If n=9, It shld print 1,2,3,5,7 7. One program on collections- Write a program to print no. of times a number is repeating in an array. EX- {1,3,1,2,5,7,3,7,34,3,8,3} It should print: 1- 2 times 3- 4 times and so on 7. Write a func to print fibonocci series After this I had technical interview, which went on for. 60 mins or so. There were qn's about multi threading, Exception handling and collection classes. Knowledge about collections was very important for the post I was interviewed for.

1 Answers   Huawei,


Is java se free?

1 Answers  


What is the size of string?

1 Answers  


Categories