Skip to content
Advertisement

Tag: string

How to convert comma-separated String to List?

Is there any built-in method in Java which allows us to convert comma separated String to some container (e.g array, List or Vector)? Or do I need to write custom code for that? Answer Convert comma separated String to List The above code splits the string on a delimiter defined as: zero or more whitespace, a literal comma, zero or

How to remove the last character from a string?

I want to remove the last character from a string. I’ve tried doing this: Getting the length of the string – 1 and replacing the last letter with nothing (deleting it), but every time I run the program, it deletes middle letters that are the same as the last letter. For example, the word is “admirer”; after I run the

Java CharAt() and deleteCharAt() performance

I’ve been wondering about the implementation of charAt function for String/StringBuilder/StringBuffer in java what is the complexity of that ? also what about the deleteCharAt() in StringBuffer/StringBuilder ? Answer For String, StringBuffer, and StringBuilder, charAt() is a constant-time operation. For StringBuffer and StringBuilder, deleteCharAt() is a linear-time operation. StringBuffer and StringBuilder have very similar performance characteristics. The primary difference is

Count words in a string method?

I was wondering how I would write a method to count the number of words in a java string only by using string methods like charAt, length, or substring. Loops and if statements are okay! I really appreciate any help I can get! Thanks! Answer

Advertisement