0

i am new in android, how can i make a string function, with input and return?

something like this :

public String (String Input)
{
    String a = "a";
    a += Input;
    return a;
}

Thank you very much

2 Answers 2

2

Exactly like that. No, seriously, just like you did above, but you need to add a name for your method:

public String MethodName (String Input)
{
    String a = "a";
    a += Input;
    return a;
}

Then you can call your method like:

String sample = MethodName("input");
Sign up to request clarification or add additional context in comments.

1 Comment

@PsylentStriker, I edited my answer if you want to know how to call your 'String' method
0

This is not related to Android in any way.

In Java this is how you declare a method:

<visibility> <some identifiers like static, final> <return type> <name>(<arguments>)
{
     <body>
}

If the return type is void you can avoid the return. If it's something else you should always return something from the function using return

So your code here miss

public String (String Input)
{
    String a = "a";
    a += Input;
    return a;
}

This method takes a String input and returns the merge with a and the string passed when the method is called.

Example:

<functionName>("Hello");

the output will be aHello

Example:

public String test(String Input)
{
    String a = "a";
    a += Input;
    return a;
}

String output = test("World");

the output variable will be aWorld

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.