"startsWith" method [closed] - java

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
It's showing unknown method "startsWith"
If it's the incorrect way then please tell the correct way
EditText editTxt = (EditText) findViewById(R.id.a);
WebView webv = (WebView) findViewById(R.id.b);
if (editTxt.startsWith("http://"){
webv.loadUrl(editTxt.getText().toString());
}else{
webv.loadUrl("http://" + editTxt.getText().toString());
}

startsWith is method of String, you need to convert to String first:
String editTxtString = editTxt.getText().toString();
if (editTxtString .startsWith("http://")) {
webv.loadUrl(editTxtString);
} else {
webv.loadUrl("http://" + editTxtString);
}
Or one liner:
webv.loadUrl(editTxtString .startsWith("http://")? editTxtString: "http://" + editTxtString);

Is editText is string class? You post to little code but try thisif editText is not String class:
if (editTxt.getText().toString().startsWith("http://"){
webv.loadUrl(editTxt.getText().toString());
}else{
webv.loadUrl("http://" + editTxt.getText().toString());
}

Related

Java Program to add two strings values [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 months ago.
Improve this question
There are Two Strings s1 and s2, then split them and add them with one another.
Please find below snippet for more information,
Input :-
String s1 ="Sheldon Cooper";
String s2 ="Howard Wolowitz";
Output :-
Sheldon Wolowitz
Howard Cooper
Can anyone help me on this....
you can use Split String method in java
String[] arrOfS1 = s1.split(" ");
String[] arrOfS2 = s2.split(" ");
System.out.println(arrOfS1[0] + " " + arrOfS2[1]);
System.out.println(arrOfS2[0] + " " + arrOfS1[1]);

why registration password only accepts # symbol? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 months ago.
Improve this question
private Boolean validatePass() {
String val = pass.getEditText().getText().toString().trim();
String passwordVal = "^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!#$%^&*-]).{8,}$";
if (val.isEmpty()) {
pass.setError("*Required");
return false;
} else if (!val.matches(passwordVal)) {
pass.setError("Invalid Password");
return false;
} else {
pass.setError(null);
return true;
}
}
I used this code for password Validation, what's wrong with this?
As per what your regex code is it should satisfy for all the symbols mentioned there #,?,!,#,$,%,^,&,*,- it will fail if you use symbols other than these like _,+,~,`

What does return "" mean? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
for (int i = 0; i < alist.size(); i++) {
if ( alist.get(i).average() == d ) {
return alist.get(i).getCountry();
}
}
return "";
}
I need to return the name of the country which is in alist.get(i).getCountry(), but when I end the body with that it will say
error: missing {
When I put return "" it doesn't have an error.
What does return "" mean?
return ""; just returns an empty string.
If you put alist.get(i).getCountry() outside of the for loop it will not make sense. (I'm assuming that's what you mean by "end the body with that.") It depends on i, which only exists in the loop.
It's tough to see why you're getting that error without seeing more of your code.

Use one String variable for Input [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I'm attempting to change the order of any given name and get an output of ("LastName, FirstName") by only using one string variable.
For example, if entered by the user as Winston Church it would print out
System.out.println("Church,Winston");
How would you combine the Full Name of the user into one or simply just use one string variable for the input? I don't wish to split it but rather combine it.
Will this work for you?
public class NameModifier {
public static void main(String []args) {
String unmodified_full_name = "FirstName LastName";
String[] full_name_array = unmodified_full_name.split(" ", 2);
System.out.println(full_name_array[1] + "," + full_name_array[0]);
}
}

How to split a string before a specific character (so that the delimiter character is in the second part of the result) [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
if I have
String a = "abc,,,";
what should I do to get
result[0].equals("abc");
result[1].equals(",,,");
The most elementary way is this:
final int pos = a.indexOf(',');
if( pos == -1 ) { // character not found, handle this case somehow }
String [] result = new String [2];
result[0]=a.substring(0, pos);
result[1]=a.substring(pos);

Categories