-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?

2
  • %s will take care of all placeholder for java? Commented Jan 15, 2012 at 1:27
  • Did you actually bother to look at the link/'s Commented Jan 15, 2012 at 1:28

1 Answer 1

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 ...

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.