Most Popular
1500 questions
4377
votes
66 answers
How do I avoid checking for nulls in Java?
I use x != null to avoid NullPointerException. Is there an alternative?
if (x != null) {
// ...
}

Goran Martinic
- 3,807
- 4
- 21
- 14
4361
votes
35 answers
How do I check if a directory exists or not in a Bash shell script?
What command checks if a directory exists or not within a Bash shell script?

Grundlefleck
- 124,925
- 25
- 94
- 111
4350
votes
42 answers
Change an HTML input's placeholder color with CSS
Chrome v4 supports the placeholder attribute on input[type=text] elements (others probably do too).
However, the following CSS doesn't do anything to the placeholder's value:
input[placeholder], [placeholder], *[placeholder] {
color: red…

David Murdoch
- 87,823
- 39
- 148
- 191
4346
votes
27 answers
How do I copy to the clipboard in JavaScript?
How do I copy text to the clipboard (multi-browser)?
Related: How does Trello access the user's clipboard?

Santiago Corredoira
- 47,267
- 10
- 52
- 56
4339
votes
34 answers
How to enumerate an enum?
How can you enumerate an enum in C#?
E.g. the following code does not compile:
public enum Suit
{
Spades,
Hearts,
Clubs,
Diamonds
}
public void EnumerateAllSuitsDemoMethod()
{
foreach (Suit suit in Suit)
{
…

Ian Boyd
- 246,734
- 253
- 869
- 1,219
4319
votes
44 answers
Finding the index of an item in a list
Given a list ["foo", "bar", "baz"] and an item in the list "bar", how do I get its index 1?

Eugene M
- 47,557
- 14
- 38
- 44
4316
votes
128 answers
How to close/hide the Android soft keyboard programmatically?
I have an EditText and a Button in my layout.
After writing in the edit field and clicking on the Button, I want to hide the virtual keyboard when touching outside the keyboard. I assume that this is a simple piece of code, but where can I find an…

Vidar Vestnes
- 42,644
- 28
- 86
- 100
4287
votes
35 answers
What are the differences between a HashMap and a Hashtable in Java?
What are the differences between a HashMap and a Hashtable in Java?
Which is more efficient for non-threaded applications?

dmanxiii
- 51,473
- 10
- 33
- 23
4230
votes
1 answer
The Definitive C++ Book Guide and List
This question attempts to collect the few pearls among the dozens of bad C++ books that are published every year.
Unlike many other programming languages, which are often picked up on the go from tutorials found on the Internet, few are able to…

grepsedawk
- 5,959
- 5
- 24
- 22
4222
votes
38 answers
How do I UPDATE from a SELECT in SQL Server?
In SQL Server, it is possible to insert rows into a table with an INSERT.. SELECT statement:
INSERT INTO Table (col1, col2, col3)
SELECT col1, col2, col3
FROM other_table
WHERE sql = 'cool'
Is it also possible to update a table with SELECT? I…

jamesmhaley
- 44,484
- 11
- 36
- 49
4214
votes
37 answers
How do I delete a commit from a branch?
How do I delete a commit from my branch history? Should I use git reset --hard HEAD?

hap497
- 154,439
- 43
- 83
- 99
4207
votes
19 answers
Undoing a git rebase
How do I easily undo a git rebase? A lengthy manual method is:
checkout the commit parent to both of the branches
create and checkout a temporary branch
cherry-pick all commits by hand
reset the faulty rebased branch to point to the temporary…

webmat
- 58,466
- 12
- 54
- 59
4204
votes
17 answers
Iterating over dictionaries using 'for' loops
d = {'x': 1, 'y': 2, 'z': 3}
for key in d:
print(key, 'corresponds to', d[key])
How does Python recognize that it needs only to read the key from the dictionary? Is key a special keyword, or is it simply a variable?

TopChef
- 43,745
- 10
- 28
- 27
4171
votes
32 answers
How to insert an item into an array at a specific index?
I am looking for a JavaScript array insert method, in the style of:
arr.insert(index, item)
Preferably in jQuery, but any JavaScript implementation will do at this point.

tags2k
- 82,117
- 31
- 79
- 106
4170
votes
35 answers