Found 346 Articles for Java Programming

What does the method fill(obj[], object val) do?

Sharon Christine
Updated on 13-Mar-2020 04:56:12

110 Views

The fill(Object[] a, Object val) method of the java.util.Arrays class assigns the specified Object reference to each element of the specified array of Objects.Exampleimport java.util.Arrays; public class ArrayDemo {    public static void main(String[] args) {       Object arr[] = new Object[] {10.5, 5.6, 4.7, 2.9, 9.7};       System.out.println("Actual values: ");       for (Object value : arr) {          System.out.println("Value = " + value);       }       Arrays.fill(arr, 12.2);       System.out.println("New values after using fill() method: ");       for (Object value : arr) {          System.out.println("Value = " + value);       }    } }OutputActual values: Value = 10.5 Value = 5.6 Value = 4.7 Value = 2.9 Value = 9.7 New values after using fill() method: Value = 12.2 Value = 12.2 Value = 12.2 Value = 12.2 Value = 12.2

What does the method toString(int[] a) do?

karthikeya Boyini
Updated on 13-Mar-2020 05:03:01

37 Views

The toString(int[]) method of the class java.util.Arrays return a string representation of the contents of the specified int array. The string representation consists of a list of the array's elements, enclosed in square brackets ("[]"). Adjacent elements are separated by the characters ", " (a comma followed by a space).Exampleimport java.util.Arrays; public class ArrayDemo {    public static void main(String[] args) {       int[] i1 = new int[] { 33, 12, 98 };       System.out.println("The array is:");       for (int number : i1) {          System.out.println("Number = " + number);   ... Read More

What is meant by a multithreaded program in Java?

Sharon Christine
Updated on 13-Mar-2020 04:54:40

209 Views

A multi-threaded program contains two or more parts that can run concurrently and each part can handle a different task at the same time making optimal use of the available resources specially when your computer has multiple CPUs.Multi-threading enables you to write in a way where multiple activities can proceed concurrently in the same program.Exampleclass RunnableDemo implements Runnable {    private Thread t;    private String threadName;       RunnableDemo( String name) {          threadName = name;          System.out.println("Creating " + threadName);       }       public void run() { ... Read More

How to convert an input stream to byte array in java?

Syed Javed
Updated on 06-Mar-2020 05:07:10

851 Views

The InputStream class in Java provides read() method. This method accepts a byte array and it reads the contents of the input stream to the given byte array.ExampleLive Demoimport java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; public class StreamToByteArray {     public static void main(String args[]) throws IOException{            InputStream is = new BufferedInputStream(System.in);        byte [] byteArray = new byte[1024];        System.out.println("Enter some data");        is.read(byteArray);              String s = new String(byteArray);        System.out.println("Contents of the byte stream are :: "+ s);   ... Read More

What is a Multidimensional array in Java?

Monica Mona
Updated on 07-Mar-2024 16:48:43

2K+ Views

In Java, a multi-dimensional array is nothing but an array of arrays.2D array − A two-dimensional array in Java is represented as an array of one-dimensional arrays of the same type. Mostly, it is used to represent a table of values with rows and columns −Int[][] myArray = {{10, 20, 30}, {11, 21, 31}, {12, 22, 32} }In short, a two-dimensional array contains one-dimensional arrays of elements. It is represented by two indices where the first index denotes the position of the array and the second index represents the position of the element within that particular array − Example ... Read More

What is the character wrapper class and its methods in Java?

Syed Javed
Updated on 30-Jul-2019 22:30:22

5K+ Views

The Character class of the java.lang package wraps a value of the primitive datatype char. It offers a number of useful class (i.e., static) methods for manipulating characters. You can create a Character object with the Character constructor. Character ch = new Character('a'); Following are the notable methods of the Character class. 1 isLetter() Determines whether the specified char value is a letter. 2 isDigit() Determines whether the specified char value is a digit. 3 isWhitespace() Determines whether the specified char value is white space. 4 isUpperCase() Determines ... Read More

Advertisements