- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to fill elements in a short array
Elements can be filled in a short array using the java.util.Arrays.fill() method. This method assigns the required short value to the short array in Java. The two parameters required are the array name and the value that is to be stored in the array elements.
A program that demonstrates this is given as follows −
Example
import java.util.Arrays; public class Demo { public static void main(String[] argv) throws Exception { short[] shortArray = new short[5]; short shortValue = 1; Arrays.fill(shortArray, shortValue); System.out.println("The short array content is: " + Arrays.toString(shortArray)); } }
Output
The short array content is: [1, 1, 1, 1, 1]
Now let us understand the above program.
First the short array shortArray[] is defined. Then the value 1 is filled in the short array using the Arrays.fill() method. Finally, the short array is printed using the Arrays.toString() method. A code snippet which demonstrates this is as follows −
short[] shortArray = new short[5]; short shortValue = 1; Arrays.fill(shortArray, shortValue); System.out.println("The short array content is: " + Arrays.toString(shortArray));
- Related Articles
- Java Program to fill elements in a float array
- Java Program to fill elements in a char array
- Java Program to fill elements in a long array
- Java Program to fill elements in a byte array
- Java Program to fill elements in an int array
- Java Program to sort Short array
- Fill elements in a Java double array in a specified range
- Fill elements in a Java long array in a specified range
- Fill elements in a Java byte array in a specified range
- Fill elements in a Java float array in a specified range
- Fill elements in a Java int array in a specified range
- Fill elements in a Java char array in a specified range
- Java Program to fill an array with random numbers
- Java Program to sort a subset of array elements
- Java Program to compare Two Java short Arrays

Advertisements