Found 4336 Articles for Java 8

Java Program to fill elements in a float array

Nancy Den
Updated on 26-Jun-2020 07:27:32

199 Views

Elements can be filled in a float array using the java.util.Arrays.fill() method. This method assigns the required float value to the float 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 Live Demoimport java.util.Arrays; public class Demo {    public static void main(String[] argv) throws Exception {       float[] floatArray = new float[5];       float floatValue = 8.5F;       Arrays.fill(floatArray, floatValue);       System.out.println("The float array content is: " + Arrays.toString(floatArray)); ... Read More

Medium length style format for Date with Java MessageFormat class

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

117 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 26-Jun-2020 07:30:45

622 Views

Binary search on a char array can be implemented by using the method java.util.Arrays.binarySearch(). 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.A program that demonstrates this is given as follows −Example Live Demoimport java.util.Arrays; public class Demo {    public static void main(String[] args) {       char c_arr[] = { 'b', 's', 'l', 'e', 'm' };       Arrays.sort(c_arr);       System.out.print("The sorted array ... Read More

Long style format for Date with Java MessageFormat class

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

186 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

485 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

173 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

223 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

789 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

966 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

Arjun Thakur
Updated on 26-Jun-2020 09:12:34

4K+ Views

In order to get the ID of this timezone in Java, we use the getDisplayName() method. The getDisplayName() returns a name of this time zone acceptable for display to the user in the default locale. In other words, the name returned by the getDisplayName() is user friendly.Declaration − The java.util.TimeZone.getDisplayName() is declared as follows −public final String getDisplayName()Let us see a program to get the ID of this timezone in Java −Example Live Demoimport java.util.*; public class Example {    public static void main( String args[] ) {       // creating default object of TimeZone       TimeZone ... Read More

Advertisements