Skip to content
Advertisement

Tag: arrays

How to trim out an array of integers in Java?

Let’s that I have a number N. N will be the size of the array. However, the contents of the array will hold every other number from 1 to positive N. This means that the entire size N array will not be full after that for loop. So after the for loop, I want to trim (or resize) the array

Calculate average of a huge long array

I’m trying to calculate the average of many (more than 200) long (primitive type) values stored in an array. Usually you add all the numbers and divide it by the number of the values. But this is not possible in this case since there is no primitive datatype in Java capable of holding such a large number, isn’t it? Will

Setting all values in a boolean array to true

Is there a method in Java for setting all values in a boolean array to true? Obviously I could do this with a for loop, but if I have (for example) a large 3D array, I imagine using a loop would be quite inefficient. Is there any method in Java to set all values in a certain array to true,

How can I shuffle the letters of a word?

What is the easiest way to shuffle the letters of a word which is in an array? I have some words in an array and I choose randomly a word but I also want to shuffle the letters of it. I am not supposed to use that List thing. I’ve come up with something like this but with this code

Java Array of unique randomly generated integers

I have a method above which should generate an array of random elements that the user specifies. The randomly generated integers should be between 0 and 10 inclusive. I am able to generate random integers but the problem I have is checking for uniqueness. My attempt to check for uniqueness is in my code above but the array still contains

Advertisement