Most Popular
1500 questions
3937
votes
45 answers
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 within it, what is the most efficient way of going through the map?
Will the ordering of elements depend on the specific map implementation…

iMack
- 38,281
- 3
- 21
- 19
3929
votes
54 answers
How do I check for an empty/undefined/null string in JavaScript?
Is there a string.Empty in JavaScript, or is it just a case of checking for ""?

casademora
- 67,775
- 17
- 69
- 78
3922
votes
7 answers
How do I clone a specific Git branch?
Git clone will clone remote branch into local.
Is there any way to clone a specific branch by myself without switching branches on the remote repository?

Scud
- 41,923
- 8
- 26
- 18
3914
votes
20 answers
How do I tell if a file does not exist in Bash?
This checks if a file exists:
#!/bin/bash
FILE=$1
if [ -f $FILE ]; then
echo "File $FILE exists."
else
echo "File $FILE does not exist."
fi
How do I only check if the file does not exist?

Bill the Lizard
- 398,270
- 210
- 566
- 880
3897
votes
25 answers
Using global variables in a function
How do I create or use a global variable inside a function?
How do I use a global variable that was defined in one function inside other functions?
Failing to use the global keyword where appropriate often causes UnboundLocalError. The precise…

user46646
- 153,461
- 44
- 78
- 84
3893
votes
42 answers
How do I test for an empty JavaScript object?
After an AJAX request, sometimes my application may return an empty object, like:
var a = {};
How can I check whether that's the case?

falmp
- 39,347
- 3
- 21
- 18
3884
votes
50 answers
How do I get the current branch name in Git?
How do I get the name of the current branch in Git?

mike628
- 45,873
- 18
- 40
- 57
3862
votes
44 answers
What are the differences between a pointer variable and a reference variable?
What is the difference between a pointer variable and a reference variable?

prakash
- 58,901
- 25
- 93
- 115
3861
votes
33 answers
Is floating point math broken?
Consider the following code:
0.1 + 0.2 == 0.3 -> false
0.1 + 0.2 -> 0.30000000000000004
Why do these inaccuracies happen?

Cato Johnston
- 44,131
- 10
- 39
- 42
3856
votes
32 answers
3856
votes
13 answers
Move existing, uncommitted work to a new branch in Git
I started some work on a new feature and after coding for a bit, I decided this feature should be on its own branch.
How do I move the existing uncommitted changes to a new branch and reset my current one?
I want to reset my current branch while…

Dane O'Connor
- 75,180
- 37
- 119
- 173
3837
votes
12 answers
Why don't Java's +=, -=, *=, /= compound assignment operators require casting long to int?
Until today, I thought that for example:
i += j;
Was just a shortcut for:
i = i + j;
But if we try this:
int i = 5;
long j = 8;
Then i = i + j; will not compile but i += j; will compile fine.
Does it mean that in fact i += j; is a shortcut for…

Honza Brabec
- 37,388
- 4
- 22
- 30
3823
votes
17 answers
Why is char[] preferred over String for passwords?
In Swing, the password field has a getPassword() (returns char[]) method instead of the usual getText() (returns String) method. Similarly, I have come across a suggestion not to use String to handle passwords.
Why does String pose a threat to…

Ahamed
- 39,245
- 13
- 40
- 68
3791
votes
14 answers
Remove a file from a Git repository without deleting it from the local filesystem
I want to remove a file from my repository.
git rm file_to_remove.txt
will remove the file from the repository, but it will also remove the file from the local file system. How do I remove this file from the repo without deleting my local copy of…

mveerman
- 38,827
- 3
- 22
- 14
3789
votes
27 answers
View the change history of a file using Git versioning
How do I view the history of an individual file with complete details of what has changed?
git log -- [filename] shows me the commit history of a file, but how do I see the file content that changed?

Richard
- 39,052
- 6
- 25
- 29