0

Hi I'm new to java so this is going to seem a bit tame. Anyway, in objC, when I want to insert a variable into a string, I would do it like this:

NSString *string = [NSString stringWithFormat:@"test%i", variable];

How do I do this in java?

2 Answers 2

8

There are number of ways, but the java.lang.String.format() method is an easy one:

String message = String.format("There are %d ways to leave your lover", 50);
Sign up to request clarification or add additional context in comments.

Comments

2

Using the String.format() method. Take a look at the documentation for understanding all the different formatting options available.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.