Maruthi Krishna has Published 951 Articles

How can we replace specific part of String and StringBuffer in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 10-Sep-2019 13:33:41

218 Views

The String class of the java.lang package represents a set of characters. All string literals in Java programs, such as "abc", are implemented as instances of this class.Example Live Demopublic class StringExample {    public static void main(String[] args) {       String str = new String("Hello how are you"); ... Read More

How to trim white space in StringBuffer in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 10-Sep-2019 13:28:48

2K+ Views

The String class of the java.lang package represents a set of characters. All string literals in Java programs, such as "abc", are implemented as instances of this class. Strings objects are immutable, once you create a String object you cannot change their values, if you try to do so instead ... Read More

How can we check if specific string occurs multiple times in another string in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 10-Sep-2019 13:24:09

2K+ Views

You can find whether a String contains a specified sequence of characters using any of the methods −The indexOf() method − The indexOf() method of the String class accepts a string value and finds the (starting) index of it in the current String and returns it. This method returns -1 if ... Read More

How can we split a string by sentence as a delimiter in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 10-Sep-2019 13:16:45

10K+ Views

The split() method of the String class accepts a String value representing the delimiter and splits into an array of tokens (words), treating the string between the occurrence of two delimiters as one token.For example, if you pass single space “ ” as a delimiter to this method and try ... Read More

Can I define more than one public class in a Java package?

Maruthi Krishna

Maruthi Krishna

Updated on 10-Sep-2019 12:45:18

6K+ Views

No, while defining multiple classes in a single Java file you need to make sure that only one class among them is public. If you have more than one public classes a single file a compile-time error will be generated.ExampleIn the following example we have two classes Student and AccessData ... Read More

Which packages contain Wrapper class in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 10-Sep-2019 12:42:21

1K+ Views

Java provides certain classes called wrapper classes in the java.lang package. The objects of these classes wrap primitive datatypes within them. Following is the list of primitive data types and their respective classes −Primitive datatypeWrapper classcharCharacterbyteByteshortShortintIntegerlongLongfloatFloatdoubleDoublebooleanBooleanPackageWrapper classes in Java belong to the java.lang package, Therefore there is no need to ... Read More

How to read data from one file and print to another file in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 10-Sep-2019 12:38:40

3K+ Views

Java provides I/O Streams to read and write data where a Stream represents an input source or an output destination which could be a file, i/o devise, other programs, etc.In general, a Stream will be an input stream or, an output stream.InputStream − This is used to read data from ... Read More

How to read/write data from/to .properties file in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 10-Sep-2019 12:33:06

10K+ Views

The .properties is an extension in java which is used to store configurable application. It is represented by the Properties class in Java, you can store a properties file and read from it using the methods of this class. This class inherits the HashTable class.Creating a .properties file −To create ... Read More

Exception Hierarchy in case of multiple catch blocks.

Maruthi Krishna

Maruthi Krishna

Updated on 10-Sep-2019 12:28:11

5K+ Views

An exception is an issue (run time error) that occurred during the execution of a program. When an exception occurred the program gets terminated abruptly and, the code past the line that generated the exception never gets executed.Multiple exceptions in a codeWhenever we have a code that may generate more ... Read More

How to find the Strings within a text file in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 10-Sep-2019 12:18:24

6K+ Views

Following Java program accepts a String value from the user, verifies whether a file contains the given String and prints the number of occurrences of the word too.Example Live Demoimport java.io.FileInputStream; import java.io.FileNotFoundException; import java.util.Scanner; public class FindingWordFromFile {    public static void main(String args[]) throws FileNotFoundException {       ... Read More

Advertisements