Latest questions in Java

0 votes
1 answer

Static Map initialization in Java

I would suggest you to use the ...READ MORE

May 4, 2018 in Java by Akrati
• 3,190 points
12,461 views
0 votes
2 answers

How to read a text file in Java?

You can use Scanner class to read ...READ MORE

Aug 9, 2018 in Java by Parth
• 4,630 points
773 views
0 votes
1 answer

How to calculate the difference between two date instances in Java?

You can use Joda Time Library. Interval i ...READ MORE

May 4, 2018 in Java by Parth
• 4,630 points
767 views
0 votes
2 answers

How does '&&' (AND) and '||' (OR) statements work inside an IF condition ?

Short circuit here means that the second ...READ MORE

Sep 19, 2018 in Java by Sushmita
• 6,910 points
637 views
0 votes
2 answers

Store String inside a File using Java

We can use Apache Commons IO. It ...READ MORE

Jul 20, 2018 in Java by Sushmita
• 6,910 points
1,084 views
0 votes
6 answers

How can I separate the digits of an int number in Java?

You can also have a look here: To ...READ MORE

Dec 9, 2020 in Java by Roshni
• 10,520 points
203,775 views
0 votes
2 answers

How can I get the filenames of all files in a folder which may or may not contain duplicates

List<String> results = new ArrayList<String>(); File[] files = ...READ MORE

Sep 12, 2018 in Java by Sushmita
• 6,910 points
1,642 views
+1 vote
2 answers

What are inner classes and static nested classes?

Nested classes are divided into two categories: ...READ MORE

Dec 3, 2018 in Java by Sushmita
• 6,910 points
3,632 views
0 votes
2 answers

Does the finally block always execute in Java?

public static void main(String[] args) { ...READ MORE

Aug 8, 2018 in Java by Sushmita
• 6,910 points
1,749 views
0 votes
3 answers

Increment the date in Java by 1-day

import java.time.LocalDate; public class DateIncrementer { static ...READ MORE

Aug 1, 2018 in Java by Akrati
• 3,190 points
4,238 views
0 votes
1 answer

Reflection: Explanation and Uses

Reflection API is used to modify or examine the behavior ...READ MORE

May 2, 2018 in Java by sharth
• 3,370 points
519 views
0 votes
2 answers

How to break the nested loop in Java?

You can use break with a label for the ...READ MORE

Sep 20, 2018 in Java by Sushmita
• 6,910 points
950 views
0 votes
1 answer

How can I read a large text file line by line using Java?

// Open the file FileInputStream file = new ...READ MORE

May 2, 2018 in Java by Parth
• 4,630 points
696 views
0 votes
2 answers

Date format conversion in Java

Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, 1); Date date = ...READ MORE

Aug 13, 2018 in Java by Sushmita
• 6,910 points
724 views
0 votes
1 answer

How to pad string in Java?

Padding to 10 characters: String.format("%10s", "foo").replace(' ', '*'); String.format("%-10s", ...READ MORE

May 1, 2018 in Java by Rishabh
• 3,620 points
804 views
0 votes
1 answer

What is the difference between Runnable and extends Thread

Runnable is the preferred way to create ...READ MORE

May 1, 2018 in Java by sharth
• 3,370 points
910 views
0 votes
2 answers

Remove duplicate elements from an ArrayList in Java

List<String> al = new ArrayList<>(); // add elements ...READ MORE

Jul 26, 2018 in Java by Sushmita
• 6,910 points
1,248 views
0 votes
1 answer

What do we understand from string pool in java?

This prints true (even though we don't use equals method: correct ...READ MORE

Apr 30, 2018 in Java by Daisy
• 8,120 points
447 views
0 votes
1 answer

Can Static methods be inherited in java?

A subclass inherits all of the public ...READ MORE

Apr 30, 2018 in Java by Daisy
• 8,120 points
1,653 views
0 votes
1 answer

What are optional parameters in Java

Using three dots: public void move(Object... x) { ...READ MORE

Apr 27, 2018 in Java by developer_1
• 3,320 points
657 views
0 votes
2 answers

How can I invoke a method when the method name is in the form of a given string?

You could probably use method invocation from reflection: Class<?> ...READ MORE

Aug 19, 2019 in Java by Sirajul
• 59,230 points
2,585 views
0 votes
3 answers

How to check whether a string is empty or not? Is there a function for this?

str != null && str.length() != 0 alternatively str ...READ MORE

Sep 11, 2018 in Java by Sushmita
• 6,910 points
1,004 views
+1 vote
1 answer

concat() vs “+” operator : In Java for String concatenation

Basically, there are two important differences between ...READ MORE

Apr 27, 2018 in Java by Rishabh
• 3,620 points
4,466 views
0 votes
4 answers

How can we compare dates in java?

public static String daysBetween(String day1, String day2) ...READ MORE

Sep 5, 2018 in Java by Sushmita
• 6,910 points
977 views
0 votes
3 answers

Is it possible to take char input from scanner?

// Use a BufferedReader to read characters ...READ MORE

Sep 7, 2018 in Java by Daisy
• 8,120 points
8,552 views
0 votes
2 answers

When to use Static Methods in Java?

A static method has two main purposes: For ...READ MORE

Aug 10, 2018 in Java by samarth295
• 2,220 points
15,555 views
+16 votes
25 answers

How can I convert String to JSON object in Java?

Hi @Daisy You can use Google gson  for more ...READ MORE

Feb 7, 2019 in Java by Suresh
• 720 points
250,603 views
0 votes
2 answers

what is the best way to convert an ArrayList to a String

You could probably use the Joiner class ...READ MORE

Aug 19, 2019 in Java by Sirajul
• 59,230 points
949 views
0 votes
2 answers

Send HTTP request in Java

import com.google.api.client.http.GenericUrl; import com.google.api.client.http.HttpRequest; import com.google.api.client.http.HttpResponse; import com.google.api.client.http.HttpTransport; import com.google.api.client.http.javanet.NetHttpTransport; import java.io.IOException; import ...READ MORE

Aug 3, 2018 in Java by samarth295
• 2,220 points
1,497 views
0 votes
2 answers

What's the best way to check if a String represents an integer in Java?

You can also use regular expression. str.matches("-?\\d+"); It will ...READ MORE

Aug 9, 2018 in Java by Daisy
• 8,120 points
3,464 views
0 votes
2 answers

How do I replace character from string at specific indexes?

You could turn the String into a ...READ MORE

Aug 22, 2019 in Java by Sirajul
• 59,230 points
22,469 views
0 votes
2 answers

How to round a double to 2 decimal places?

double value = 200.3456; System.out.printf("Value: %.2f", value); You can ...READ MORE

Dec 11, 2018 in Java by Sushmita
• 6,910 points
13,963 views
0 votes
1 answer

How can I create an executable JAR with dependencies using Maven?

<build> <plugins> <plugin> ...READ MORE

Apr 26, 2018 in Java by sophia
• 1,400 points
989 views
0 votes
2 answers

What is the difference between Set and List in java?

List is an ordered sequence of elements. ...READ MORE

Apr 26, 2018 in Java by Akrati
• 3,190 points
62,738 views
0 votes
2 answers

What is the difference between = and equals()?

The equals() method compares the "value" inside String instances ...READ MORE

Aug 13, 2018 in Java by Daisy
• 8,120 points
1,104 views
0 votes
1 answer

difference between wait() and sleep() in java

We can find a big difference between ...READ MORE

Apr 26, 2018 in Java by developer_1
• 3,320 points
875 views
0 votes
2 answers

What is the use of toString method in Java and how can I use it ?

Whenever you require to explore the constructor ...READ MORE

Aug 23, 2018 in Java by Daisy
• 8,120 points
3,795 views
0 votes
2 answers

How do I convert an input stream into a byte array

You could probably try this if you ...READ MORE

Aug 29, 2019 in Java by Sirajul
• 59,230 points
3,366 views
0 votes
2 answers

Counting no of Occurrence of a particular character inside a string in Java

We can find out the no. of ...READ MORE

Sep 7, 2018 in Java by Sushmita
• 6,910 points
2,308 views
0 votes
2 answers

How can I get current time in YYYY:MM:DD HH:MI:Sec:Millisecond format in Java?

public String getCurrentTimeStamp() { ...READ MORE

Sep 21, 2018 in Java by Parth
• 4,630 points
6,787 views
0 votes
2 answers

How to find out current working directory in Java?

You can also use java.nio.file.Path and java.nio.file.Paths. Path ...READ MORE

Jul 31, 2018 in Java by Sushmita
• 6,910 points
721 views
0 votes
2 answers

Array of Objects

You can also do : A[] a = ...READ MORE

Aug 3, 2018 in Java by sharth
• 3,370 points
511 views
0 votes
2 answers

Copying Objects in Java

class DummyBean { private String dummy; ...READ MORE

Aug 6, 2018 in Java by Sushmita
• 6,910 points
500 views
0 votes
2 answers

How to convert array into list in Java?

Another workaround if you use apache commons-lang: int[] ...READ MORE

Aug 10, 2018 in Java by samarth295
• 2,220 points
671 views
0 votes
2 answers

How to concatenate two arrays in Java?

public <T> T[] concatenate(T[] a, T[] b) ...READ MORE

Jul 19, 2018 in Java by Sushmita
• 6,910 points
2,426 views
0 votes
1 answer

what are the ways in which a list can be iterated

  There are 5 ways to iterate over ...READ MORE

Apr 23, 2018 in Java by sharth
• 3,370 points
927 views
0 votes
1 answer

How can I Sort an ArrayList in Java

You can sort the ArrayList in 2 ...READ MORE

Apr 23, 2018 in Java by sharth
• 3,370 points
688 views
0 votes
1 answer

What is the difference between jdk and jre?

JRE: It stands for Java Runtime Environment. ...READ MORE

Apr 20, 2018 in Java by Akrati
• 3,190 points
1,686 views
0 votes
2 answers

What is the difference between implements and extends?

Extends : This is used to get attributes ...READ MORE

Aug 3, 2018 in Java by samarth295
• 2,220 points
15,275 views
0 votes
2 answers

How can I convert an 'ArrayList<String> to 'String[]' in Java

In Java 8 or later: String listString = ...READ MORE

Aug 20, 2019 in Java by Sirajul
• 59,230 points
2,857 views