All Questions

727
votes
23answers
2662841 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 ...
2405
votes
72answers
1822775 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...
583
votes
10answers
258013 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...
169
votes
8answers
152861 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)...
1063
votes
30answers
2561896 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...
430
votes
20answers
648372 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...
632
votes
13answers
1254832 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...
230
votes
26answers
273082 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?
392
votes
12answers
232091 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 ...
1634
votes
34answers
871723 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