How to sort a string in Android [closed] - android

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a string like "RSEBAK" and I'd like to sort that string to "ABEKRS"
Is it possible in android?
If it is, then please guide me through.

Your spec is a bit fuzzy, but I think you mean to sort the charters in a string? If so…
String s1 = "RSEBAK";
char[] arrC = s1.toCharArray();
Arrays.sort(arrC);
String strSorted = new String(arrC);
strSorted should have "ABEKRS"

Related

Again N Again Split the string with "#" [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I want to split the String with the # symbol
'#Happy#sad#Angry#Tear and so on`
I don't know how many times user enters hashtags so how can I split that String?
I tried this:
allhashtag= String.valueOf(edt_hashtag.getText());
String tag1[] =allhashtag.split("#");
String tag2= tag1[0];
Try for loop for split String when we don't know how many characters in String
Try this code:
String s = allhashtag;
if(s.toString().contains("#"))
{
String tags[]=s.toString().split("#");
for (String tag : tags)
{
Log.e("tag",""+tag);
}
}

Why the .whereEqualTo isn't working? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
Why this working
Query firstQuery1 = firebaseFirestore.collection("Test").whereEqualTo("test", "1");
And this isn't working
Query firstQuery1 = firebaseFirestore.collection("Test");
firstQuery1.whereEqualTo("test", "1");
firestore.collection("Test") returns an object of type CollectionReference while ref.whereEqualTo(..) returns a Query
So instead of
Query firstQuery1 = firestore.collection("Test");
firstQuery1.whereEqualTo("test", "1");
it needs to be
CollectionReference ref = firestore.collection("Test");
Query query = ref.whereEqualTo("test","1");

Why I am not getting the correct output for array.set? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
Firstly, I am storing the data in ArrayList.Now based on my index(current position) I want to replace that data with new data,but what I am getting is
old data,old data,old data,true,true,new data,new data....
Any suggestions
ArrayList<String> arr = new ArrayList<String>();
if (arr.isEmpty()) {
for(int i = 0;i<=mcq.size();i++) {
arr.add(s);
}
} else {
arr.set(currentPosition, String.valueOf(arr.add(s)));
}
"s" is a String value I am getting from somewhere else.
This looks really weird:
arr.set(currentPosition, String.valueOf(arr.add(s)));
ArrayList.set changes the elements stored at currentPosition. You want it to change it to the string value of what arr.add returns.
ArrayList.add returns a boolean, so there you get your true values from.
I think you want to do arr.set(currentPosition, s);

Regular Expression in numbers and string length Android [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I need to point out the users that a number can only start from 9 and and its length is to be exactly equal to 10 digits. How do I manipulate this with a regex ? Please don't mind the question, I am relatively new.
To validate that the input is exactly 10 digits, starting with 9, use:
/^9\d{9}$/
The ^9 part matches a starting 9, {d}9 matches 9 digits
Here you are. A simple solution (not with regex):
String number = "12345";
...
if (number.length() != 10 || number.startsWith("9") == false)
{
Toast.makeText(getApplicationContext(), "Please check your input.", Toast.LENGTH_SHORT).show();
}
Hope this helps. Write if you have any problems.

How to convert Timezones in Double? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
Can anyone tell me how to get Timezones in double, actually I get timezone like this way UTC+5.30. But I want only 5.30 in double.
try
TimeZone tz = TimeZone.getDefault();
String gmt = TimeZone.getTimeZone(tz.getID()).getDisplayName(false,
TimeZone.SHORT);
String z1 = gmt.substring(4);
String z = z1.replaceAll(":", ".");
double zo = Double.parseDouble(z);
Log.d("double time", "" + zo);

Categories

Resources