Maruthi Krishna has Published 870 Articles

How to parse Date from String in the format: dd/MM/yyyy to dd/MM/yyyy in java?

Maruthi Krishna

Maruthi Krishna

Updated on 14-Oct-2019 07:46:50

15K+ Views

The java.text package provides a class named SimpleDateFormat which is used to format and parse dates in required manner (local).One of the constructors of this class accepts a String value representing the desired date format and constructors SimpleDateFormat object.The format() method of this class accepts a java.util.Date object and returns ... Read More

Is it possible to check if a String only contains ASCII in java?

Maruthi Krishna

Maruthi Krishna

Updated on 14-Oct-2019 07:37:37

2K+ Views

Using regular expressionYou can find whether a particular String value contains ASCII characters using the following regular expression −\A\p{ASCII}*\zThe matches() method of the String class accepts a regular expression and verifies whether the current string matches the given expression if so, it returns true, else it returns false.Therefore, Invoke the ... Read More

How do we initialize an array within object parameters in java?

Maruthi Krishna

Maruthi Krishna

Updated on 14-Oct-2019 07:33:00

5K+ Views

You can initialize the array variable which is declared inside the class just like any other value, either using constructor or, using the setter method.ExampleIn the following Java example, we are declaring an instance variable of array type and initializing it from the constructor. Live Demopublic class Student {    String ... Read More

How do we make my string comparison case insensitive in java?

Maruthi Krishna

Maruthi Krishna

Updated on 11-Oct-2019 08:25:47

825 Views

We can compare Strings in Java in various ways −Using the comapareTo() method − The compareTo() method compares two strings lexicographically. The comparison is based on the Unicode value of each character in the strings. The character sequence represented by this String object is compared lexicographically to the character sequence ... Read More

Can a final variable be initialized when an object is created in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 11-Oct-2019 07:38:33

1K+ Views

Once you declare a variable final, after initializing it, you cannot modify its value further. Moreover, like instance variables, final variables will not be initialized with default values.Therefore, it is mandatory to initialize final variables once you declare them. If not a compile time error will be generated.Example Live Demopublic class ... Read More

How to copy a specific section of an array in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 11-Oct-2019 07:38:13

423 Views

Using copyOf() methodThe copyOf() method of the Arrays class (java.util package) accepts two parameters −an array (of any type).an integer value representing length.And copies the contents of the given array from starting position to given length and returns the new array.Example Live Demoimport java.util.Arrays; public class CopyingSectionOfArray {    public static ... Read More

How to check if String value is Boolean type in java?

Maruthi Krishna

Maruthi Krishna

Updated on 11-Oct-2019 07:00:42

12K+ Views

The Boolean class of the lang package provides two method namely parseBoolean() and valueOf().parseBoolean(String s) − This method accepts a String variable and returns boolean. If the given string value is "true" (irrespective of its case) this method returns true else, if it is null or, false or, any other ... Read More

How to execute an external program like windows media player in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 11-Oct-2019 06:56:18

1K+ Views

Using the Runtime classJava provides a class named java.lang.Runtime, using this class you can interface with the current environment.The getRunTime() (static) method of this class returns a Runtime object associated with the current application.The exec() method accepts a String value representing the command to execute a process in the current ... Read More

How to read the contents of a web page without using any external library in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 11-Oct-2019 06:38:41

376 Views

The URL class of the java.net package represents a Uniform Resource Locator which is used to point a resource (file or, directory or a reference) in the world wide web.The openStream() method of this class opens a connection to the URL represented by the current object and returns an InputStream ... Read More

How to replace all occurrences of a word in a string with another word in java?

Maruthi Krishna

Maruthi Krishna

Updated on 10-Oct-2019 10:40:12

1K+ Views

The replaceAll() method of the String class accepts two strings, One representing a regular expression to find a string and the other representing a replacement string.And, replaces all the matched sequences with the given String. Therefore, to replace a particular word with another in a String −Get the required String.Invoke ... Read More

Advertisements