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
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");
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