Found 9326 Articles for Object Oriented Programming

Format a message with date in Java

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

471 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

169 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

215 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

766 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

947 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

Get the default Time Zone in Java

Chandu yadav
Updated on 26-Jun-2020 09:13:13

2K+ Views

In order to get the default Time Zone in Java, we use the getDefault() method. The java.util.TimeZone.getDefault() method returns the default TimeZone for the particular host. The source of the default TimeZone varies with the implementation.Declaration −The java.util.TimeZone.getDefault() method is declared as follows −public static TimeZone getDefault()Let us see a program to get the default time zone 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 object: " + obj); ... Read More

Get the IDs according to the given time zone offset in Java

George John
Updated on 26-Jun-2020 09:14:08

178 Views

In order to get the IDs according to the given time zone offset in Java, we use the getAvailableIDs(int rawOffset) method. The java.util.TimeZone.getAvailableIDs(int rawOffset) method returns the available IDs according to the given time zone offset in the arguments.Declaration − The java.util.TimeZone.getAvailableIDs(int rawOffset) method is declared as follows −public static String[] getAvailableIDs(int rawOffset)where rawOffset is the given time zone GMT offset.Let us see a Java program which gets the IDs according to the given time zone offset −Example Live Demoimport java.util.*; public class Example {    public static void main(String args[]) {       // getting available supported ids for ... Read More

Get all the IDs of the Time Zone in Java

Chandu yadav
Updated on 26-Jun-2020 09:15:09

5K+ Views

To get all the IDs of the TimeZone in Java, we use the getAvailableIDs() method. The getAvailableIDs() method returns all the available IDs which are compatible.Declaration −The java.util.TimeZone.getAvailableIDs() method is declared as follows −public static String[] getAvailableIDs()Let us see a Java program which gets all the IDs of the Time Zone:Example Live Demoimport java.util.*; public class Example {    public static void main(String args[]) {       // getting available supported ids       String[] id = TimeZone.getAvailableIDs();       // printing available ids       System.out.println("The available IDs are as follows:");       for (int ... Read More

Find maximum element of ArrayList with Java Collections

Arjun Thakur
Updated on 26-Jun-2020 09:16:38

12K+ Views

In order to compute maximum element of ArrayList with Java Collections, we use the Collections.max() method. The java.util.Collections.max() returns the maximum element of the given collection. All elements must be mutually comparable and implement the comparable interface. They shouldn’t throw a ClassCastException.Declaration −The Collections.max() method is declared as follows −public static T max(Collection c)where c is the collection object whose maximum is to be found.Let us see a program to find the maximum element of ArrayList with Java collections −Example Live Demoimport java.util.*; public class Example {    public static void main (String[] args) {       List list ... Read More

Advertisements