This question already has answers here:
How to get the last characters in a String in Java, regardless of String size
(11 answers)
Closed 4 years ago.
I have a string "Century Gothic#12,75#True#FFFFFFFF" and i would be able to retrive just the string "FFFFFFFF" so how can i use substring to get the string after the third #? or can i just start in someway to substring the String from the end?
Try this:
String s = "Century Gothic#12,75#True#FFFFFFFF";
String[] parts = s.split("#");
//parts[2] = "FFFFFFFF"
Related
This question already has answers here:
How could I split a String into an array in Kotlin?
(6 answers)
Closed 1 year ago.
val sharedPreferences90 =
getSharedPreferences("sharedPrefs90", Context.MODE_PRIVATE)
val savedString90: String? =
sharedPreferences90.getString("STRING90","null") `
Here my String is company1,company2,company3. I would like to convert it to array. How do I do that?
val result = "company1,company2,company3".split(",").toTypedArray()
This question already has answers here:
StringBuilder to Array of Strings how to convert
(2 answers)
Closed 6 years ago.
I have a string builder in Android which is filled with data from a database, and I want to display that data using a list view. For that I want to covert string builder into an array of strings. Can somebody help me in this conversion, or suggest to me some other technique.
Here you can find Link
tempArray = sb.toString().split("ABCABC"); will split the string and return an array of strings for each line.
Try this :
String sbString = sb.ToString();
String[] ary = "abc".split("TABTAB");
This question already has answers here:
Java: convert List<String> to a join()d String
(23 answers)
Closed 7 years ago.
I have a situation in which I want to convert a List<String> to a single String and with commas
PS : I'm using RootTools library for command and I wanna execute a
Busybox --list command
Just iterate over your list and add elements as they come to a String.
This is one way of doing it but there are others.
List<String> myList ;
String result = "";
//...
for (String tmp : myList) {
result += tmp+","
}
This question already has answers here:
How do I compare strings in Java?
(23 answers)
Closed 8 years ago.
I hope somebody could give me an explaination why the below code wont work:
//Why doesnt this work
String l = myString.substring(cut, lengthLastBtn-1);
String c = myString.substring(cut, lengthLastBtn-1);
if(l==c){
Log.i(TAG, "Correct");
}
//End
//This work!
String l = "hi";
String c = "hi";
if(l==c){
Log.i(TAG, "Correct");
}
// End
// Or if i want the Vars as in the first code i have to use the if statement like this
if(l.contains(c)){
Log.i(TAG, "Correct");
}
//End
So, why cant a compare a string when i have used the substring method on it. I even see in the log for the strings that they are the same, or have the same text at least.
When you use the “==“ operator with String`s, it means a comparison between objects, not the value that objects hold.
In order to compare Strings values , you should use the built-in method equals. The result is true if the String object represents the same sequence of characters.
if(string1.equals(string2)) {
//Match
}
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Inserting a Java string in another string without concatenation?
In Object C , the string formatting is like this
url = [NSString stringWithFormat:#"%#devices.json?user=%#&pswd=%#",server_name, user,password];
What about in Java for Android?
How does it handle that?
You can concatenate the strings or use String.format(String format, Object... args)
Concatenate
String url = server_name + "devices.json?user=" + user + "&pswd=" + password
Format
String url = String.format("%sdevices.json?user=%spswd=%s",server_name,user,password);
It is a matter of preference for which one you prefer.
Look up java.util.Formatter for a table that demonstrates other conversion types. %s is for string, %d for int ...