Found 33676 Articles for Programming

Java Program to fill elements in a float array

Nancy Den
Updated on 10-Feb-2025 11:34:34

385 Views

In this article, we will learn how to fill elements in a float array in Java. The Arrays.fill() method is used to assign a specified value to each element of the array. Array fill() method The Arrays.fill() method in Java sets all elements of an array to a given value, making it useful for quickly initializing or resetting arrays. The Arrays.fill() method works with various data types like int, char, double, and boolean. It makes it easy to fill arrays with a default or specific value. Syntax Arrays.fill(array, value)Arrays.fill(array, start, end, value) ... Read More

Medium length style format for Date with Java MessageFormat class

Krantik Chavan
Updated on 26-Jun-2020 07:28:36

184 Views

To format message with medium style format of date in Java, we use the MessageFormat class and the Date class. The MessageFormat class gives us a way to produce concatenated messages which are not dependent on the language. The MessageFormat class extends the Serializable and Cloneable interfaces.Declaration − The java.text.MessageFormat class is declared as follows −public class MessageFormat extends FormatThe  MessageFormat.format(pattern, params) method formats the message and fills in the missing parts using the objects in the params array matching up the argument numbers and the array indices.The format method has two arguments, a pattern and an array of arguments. ... Read More

Java program to implement binary search on char array

Anvi Jain
Updated on 29-Sep-2024 02:49:49

1K+ Views

In this article, we will learn to implement binary search on char array using Java. The binary search on a char array can be implemented by using the Arrays.binarySearch() method of java.util package. This method returns the index of the required char element if it is available in the array, otherwise, it returns (-(insertion point) - 1) where the insertion point is the position at which the element would be inserted into the array. Problem Statement Write a program in Java to implement binary search on char array Input 'b', 's', 'l', 'e', 'm' Output The sorted array is: b ... Read More

Long style format for Date with Java MessageFormat class

Smita Kapse
Updated on 26-Jun-2020 07:31:20

284 Views

To format message with long style format of date in Java, we use the MessageFormat class and the Date class. The MessageFormat class gives us a way to produce concatenated messages which are not dependent on the language. The MessageFormat class extends the Serializable and Cloneable interfaces.Declaration − The java.text.MessageFormat class is declared as follows −public class MessageFormat extends FormatThe  MessageFormat.format(pattern, params) method formats the message and fills in the missing parts using the objects in the params array matching up the argument numbers and the array indices.The format method has two arguments, a pattern and an array of arguments. ... Read More

Format a message with date in Java

Krantik Chavan
Updated on 26-Jun-2020 07:32:31

748 Views

To format the message with date in Java, we use the MessageFormat class and the Date class. The MessageFormat class gives us a way to produce concatenated messages which are not dependent on the language. The MessageFormat class extends the Serializable and Cloneable interfaces.Declaration - The java.text.MessageFormat class is declared as follows −public class MessageFormat extends FormatThe  MessageFormat.format(pattern, params) method formats the message and fills in the missing parts using the objects in the params array matching up the argument numbers and the array indices.The format method has two arguments, a pattern and an array of arguments. The pattern contains placeholder ... Read More

Format percentage with MessageFormat class in Java

Smita Kapse
Updated on 29-Jun-2020 06:16:08

252 Views

To format message with percentage fillers in Java, we use the MessageFormat class. The MessageFormat class gives us a way to produce concatenated messages which are not dependent on the language. The MessageFormat class extends the Serializable and Cloneable interfaces.Declaration - The java.text.MessageFormat class is declared as follows −public class MessageFormat extends FormatThe  MessageFormat.format(pattern, params) method formats the message and fills in the missing parts using the objects in the params array matching up the argument numbers and the array indices.The format method has two arguments, a pattern and an array of arguments. The pattern contains placeholder in {} curly ... Read More

How to format message with integer fillers in Java

Chandu yadav
Updated on 26-Jun-2020 08:09:10

386 Views

To format message with integer fillers in Java, we use the MessageFormat class. The MessageFormat class gives us a way to produce concatenated messages which are not dependent on the language. The MessageFormat class extends the Serializable and Cloneable interfaces.Declaration − The java.text.MessageFormat class is declared as follows −public class MessageFormat extends FormatThe MessageFormat.format(pattern, params) method formats the message and fills in the missing parts using the objects in the params array matching up the argument numbers and the array indices.The format method has two arguments, a pattern and an array of arguments. The pattern contains placeholder in {} curly ... Read More

Substitute tokens in a String in Java

George John
Updated on 26-Jun-2020 09:10:28

1K+ Views

To substitute tokens in a String in Java, we use the Message Format class. The Message Format class provides a means to produce concatenated messages which are not dependent on the language. The Message Format class extends the Serializable and Cloneable interfaces.Declaration − The java.text.MessageFormat class is declared as follows −public class MessageFormat extends FormatThe MessageFormat.format(pattern, params) method formats the message and fills in the missing parts using the objects in the params array matching up the argument numbers and the array indices.The format method has two arguments, a pattern and an array of arguments. The pattern contains placeholder in ... Read More

Set the base time zone offset to GMT in Java

Ankith Reddy
Updated on 26-Jun-2020 09:11:08

1K+ Views

In order to set the base time zone to GMT in Java, we use the setRawOffset(int offsetMillis) method. The java.util.TimeZone.setRawOffset(int offsetMillis) method set the base timezone offset to GMT.Declaration − The java.util.TimeZone.setRawOffset(int offsetMillis) method is declared as follows −public abstract void setRawOffset(int offsetMillis)where offsetMillis is the given base time zone offset to GMT.Let us set the base timezone offset to GMT in Java −Example Live Demoimport java.util.*; public class Example {    public static void main( String args[] ) {       // creating default object of TimeZone       TimeZone obj = TimeZone.getDefault();       System.out.println("Default timezone ... Read More

Get the ID of this timezone in Java

Revathi Satya Kondra
Updated on 14-Jan-2025 03:34:12

5K+ Views

To get the ID of the current timezone in Java, we use the ZoneId class that belongs to java.time package. This provides a way to work with different timezones and their IDs. In Java, the ZoneId class represents a time zone identifier, such as India/Europe. The ZoneId can be used to retrieve the unique ID of the current timezone. To Get the ID of this timezone in Java is quite easy. Let's learn the following methods: Using Zone Id Class Using Zone Id.systemDefault() Using TimeZone.getDefault().toZoneId() Using ... Read More

Advertisements