All Questions

727
votes
23answers
2787345 views

How do I compare strings in Java?

I've been using the == operator in my program to compare all my strings so far. However, I ran into a bug, changed one of them into .equals() instead, and it fixed the bug. Is == bad? When should it ...
2465
votes
74answers
1865711 views

The most elegant way to iterate the words of a string

What is the most elegant way to iterate the words of a string? The string can be assumed to be composed of words separated by whitespace. Note that I'm not interested in C string functions or that ki...
600
votes
10answers
265388 views

What is the difference between single-quoted and double-quoted strings in PHP?

I'm not an expert in PHP programming, but I'm a little confused why I see some code in PHP with string placed in single quotes and sometimes in double quotes. I just know in .NET, or C language, if i...
178
votes
9answers
165238 views

How do I print my Java object without getting "SomeType@2f92e0f4"?

I have a class defined as follows: public class Person { private String name; // constructor and getter/setter omitted } I tried to print an instance of my class: System.out.println(myPerson)...
1119
votes
29answers
2685304 views

How to split a string in Java

I have a string, "004-034556", that I want to split into two strings: string1=004 string2=034556 That means the first string will contain the characters before '-', and the second string will conta...
654
votes
13answers
1298862 views

Java string to date conversion

Can somebody recommend the best way to convert a string in the format 'January 2, 2010' to a date in java? Ultimately, I want to break out the month, the day, and the year as integers so that I can u...
439
votes
20answers
668402 views

Java String.equals versus ==

This code separates a string into tokens and stores them in an array of strings, and then compares a variable with the first home ... why isn't it working? public static void main(String...aArguments...
235
votes
26answers
283407 views

Evaluating a math expression given in string form

I'm trying to write a Java routine to evaluate simple math expressions from String values like: "5+3" "10-40" "10*3" I want to avoid a lot of if-then-else statements. How can I do this?
405
votes
13answers
243681 views

What is the difference between char s[] and char *s?

In C, one can do like this: char s[] = "hello"; or char *s = "hello"; So I wonder what is the difference? I want to know what actually happens for memory allocation during compile time and run ...
1698
votes
34answers
907300 views

Creating multiline strings in JavaScript

I have the following code in Ruby. I want to convert this code into JavaScript. what's the equivalent code in JS? text = <<"HERE" This Is A Multiline String HERE

Previous Next