Tag: r

53 votes
30 answers
889 views
How can I create an executable JAR with dependencies using Maven?

I want to package my project in a single executable JAR for distribution. How can I make a Maven project pack

avatar
Xavier
0 1 0 9
asked 07 September, 2021
56 votes
3 answers
1.8K views
Why is printing "B" dramatically slower than printing "#"?

I generated two matrices of 1000 x 1000: First Matrix: O and #. Second Matrix: O and B. Using the following

avatar
Shantay
0 1 0 9
asked 07 September, 2021
63 votes
30 answers
2.2K views
Initialization of an ArrayList in one line

I wanted to create a list of options for testing purposes. At first, I did this: ArrayList<String> plac

avatar
Dorian
0 1 0 9
asked 07 September, 2021
52 votes
26 answers
718 views
What is a serialVersionUID and why should I use it?

Eclipse issues warnings when a serialVersionUID is missing. The serializable class Foo does not declare

avatar
Chaya
0 1 0 9
asked 07 September, 2021
52 votes
30 answers
2.6K views
How do I convert a String to an int in Java?

How can I convert a String to an int in Java? My String contains only numbers, and I want to return the numbe

avatar
Louetta
0 1 0 9
asked 07 September, 2021
54 votes
30 answers
924 views
When to use LinkedList over ArrayList in Java?

I've always been one to simply use: List<String> names = new ArrayList<>(); I use the inte

avatar
Sena
0 1 0 9
asked 07 September, 2021
57 votes
29 answers
2K views
What is the difference between public, protected, package-private and private in Java?

In Java, are there clear rules on when to use each of access modifiers, namely the default (package private),

avatar
Lynette
0 1 0 9
asked 07 September, 2021
53 votes
30 answers
2.2K views
How can I create a memory leak in Java?

I just had an interview where I was asked to create a memory leak with Java. Needless to say, I felt pretty du

avatar
Percy
0 1 0 9
asked 07 September, 2021
67 votes
30 answers
834 views
How do I efficiently iterate over each entry in a Java Map?

If I have an object implementing the Map interface in Java and I wish to iterate over every pair contained wit

avatar
Daniel
0 1 0 9
asked 07 September, 2021
60 votes
18 answers
442 views
Why is char[] preferred over String for passwords?

In Swing, the password field has a getPassword() (returns char[]) method instead of the usual getText() (retur

avatar
Chelsea
0 1 0 9
asked 07 September, 2021
64 votes
11 answers
981 views
Why don&apos;t Java&apos;s +=, -=, *=, /= compound assignment operators require casting?

Until today, I thought that for example: i += j; Was just a shortcut for: i = i + j; But if we try this:

avatar
Jeff
0 1 0 9
asked 07 September, 2021
55 votes
30 answers
2.2K views
How do I generate random integers within a specific range in Java?

How do I generate a random int value in a specific range? I have tried the following, but those do not work: A

avatar
Patsy
0 1 0 9
asked 07 September, 2021
58 votes
11 answers
2.2K views
60 votes
30 answers
343 views
Create ArrayList from array

I have an array that is initialized like: Element[] array = {new Element(1), new Element(2), new Element(3)};

avatar
Margo
0 1 0 9
asked 07 September, 2021
50 votes
30 answers
2.6K views
Avoiding NullPointerException in Java

I use object != null a lot to avoid NullPointerException. What is an alternative to: if (someobject != null) {

avatar
Serina
0 1 0 9
asked 07 September, 2021
55 votes
30 answers
2K views
How do I read / convert an InputStream into a String in Java?

If you have a java.io.InputStream object, how should you process that object and produce a String? Suppose I

avatar
Margo
0 1 0 9
asked 07 September, 2021
52 votes
30 answers
2.2K views
Is Java "pass-by-reference" or "pass-by-value"?

I always thought Java uses pass-by-reference. However, I've seen a blog post that claims that Java uses p

avatar
Emilia
0 1 0 9
asked 07 September, 2021
63 votes
27 answers
2.9K views
Why is processing a sorted array faster than processing an unsorted array?

Here is a piece of C++ code that shows some very peculiar behavior. For some strange reason, sorting the data

avatar
Boyd
0 1 0 9
asked 07 September, 2021
69 votes
3 answers
3.1K views
58 votes
7 answers
1.7K views
CodeIgniter Active Record not equal

In CodeIgniter using active record, how do I perform a not equal to in $this->db->where(). For instance

avatar
Gigi
0 1 0 9
asked 07 September, 2021