Most Popular

1500 questions
3712
votes
18 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
  • 38,027
  • 13
  • 37
  • 68
3705
votes
42 answers

What are the differences between a pointer variable and a reference variable in C++?

I know references are syntactic sugar, so code is easier to read and write. But what is the difference between a pointer variable and a reference variable?
prakash
  • 57,297
  • 25
  • 89
  • 114
3679
votes
32 answers

How can I cast int to enum?

How can an int be cast to an enum in C#?
lomaxx
  • 109,635
  • 56
  • 141
  • 178
3674
votes
55 answers

Sort array of objects by string property value

I have an array of JavaScript objects: var objs = [ { first_nom: 'Lazslo', last_nom: 'Jamf' }, { first_nom: 'Pig', last_nom: 'Bodine' }, { first_nom: 'Pirate', last_nom: 'Prentice' } ]; How can I sort them by the value of…
Tyrone Slothrop
  • 37,031
  • 3
  • 15
  • 8
3667
votes
24 answers

Using global variables in a function

How can I create or use a global variable in a function? If I create a global variable in one function, how can I use that global variable in another function? Do I need to store the global variable in a local variable of the function which needs…
user46646
  • 144,445
  • 43
  • 74
  • 84
3664
votes
7 answers

Iterate through a HashMap

What's the best way to iterate over the items in a HashMap?
burntsugar
  • 55,934
  • 21
  • 53
  • 80
3651
votes
87 answers

How to round to at most 2 decimal places, if necessary

I'd like to round at most two decimal places, but only if necessary. Input: 10 1.7777777 9.1 Output: 10 1.78 9.1 How can I do this in JavaScript?
stinkycheeseman
  • 39,309
  • 7
  • 28
  • 49
3644
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
  • 38,933
  • 7
  • 24
  • 18
3640
votes
123 answers

Message 'src refspec master does not match any' when pushing commits in Git

I clone my repository with: git clone ssh://xxxxx/xx.git But after I change some files and add and commit them, I want to push them to the server: git add xxx.php git commit -m "TEST" git push origin master But the error I get back is: error: src…
sinoohe
  • 36,756
  • 3
  • 17
  • 16
3623
votes
32 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
  • 41,471
  • 10
  • 38
  • 42
3619
votes
11 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
  • 71,622
  • 37
  • 116
  • 167
3603
votes
51 answers

How can I check for an empty/undefined/null string in JavaScript?

I saw this question, but I didn't see a JavaScript specific example. Is there a simple string.Empty available in JavaScript, or is it just a case of checking for ""?
casademora
  • 64,193
  • 16
  • 68
  • 78
3590
votes
10 answers

Does Python have a string 'contains' substring method?

I'm looking for a string.contains or string.indexof method in Python. I want to do: if not somestring.contains("blah"): continue
Blankman
  • 248,432
  • 309
  • 736
  • 1,161
3585
votes
60 answers

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 dumb having no clue on how to even start creating one. What would an example be?
MatBanik
  • 25,486
  • 39
  • 112
  • 177
3568
votes
30 answers

Set cellpadding and cellspacing in CSS?

In an HTML table, the cellpadding and cellspacing can be set like this: How can the same be accomplished using CSS?
kokos
  • 41,986
  • 5
  • 34
  • 32