-1

Possible Duplicate:
Inserting a Java string in another string without concatenation?

In Object C , the string formatting is like this

 url = [NSString stringWithFormat:@"%@devices.json?user=%@&pswd=%@",server_name, user,password];

What about in Java for Android? How does it handle that?

Community
  • 1
  • 1
jason hong
  • 435
  • 1
  • 7
  • 12

1 Answers1

0

You can concatenate the strings or use String.format(String format, Object... args)

Concatenate

String url = server_name + "devices.json?user=" + user + "&pswd=" + password

Format

String url = String.format("%sdevices.json?user=%spswd=%s",server_name,user,password);

It is a matter of preference for which one you prefer.

Look up java.util.Formatter for a table that demonstrates other conversion types. %s is for string, %d for int ...

Jesse Black
  • 7,966
  • 3
  • 34
  • 45