Skip to content
Advertisement

Tag: string

Differences between W, \W, [^a-zA-Z0-9_] in regular expression

I am trying to find all characters, which are not letters(upper/lowercase), numbers, and underscore, and remove it. However, the following code could not even compile in Java: If I use only “\W” rather than “W”, the above code turns out to be correct. So, what is the differences between W, \W, and when to use brackets like [^a-zA-Z0-9_] Answer However,

Coding Bat Recursion exercise (java)

How can I solve this problem recursively instead of using the replace method? I’m trying to get better a recursive methods. Given a string, compute recursively (no loops) a new string where all the lowercase ‘x’ chars have been changed to ‘y’ chars. I cheated and solved it this way and tried to look at the source code for Java

Why show java.lang.ClassCastException: android.text.SpannableString cannot be cast to java.lang.String?

When copying String from any browser page, pasteData works properly. However when copying SpannedString from a message sent item editor(field), the application crashes and shows this error message: My code: where the ClipboardManager instance defined as clipBoard, below: All I’m trying to do is use pasteData in String format. How to get rid of this error? Any help is appreciated.

contains() method not working as expected

I am building a voice assistant for android, here this method retrieves contact names one by one and compares it to to SpeechToText input. I am successfully getting the contact names, but when I am comparing it with my input text, nothing is happening. Here is the code Here for example I sending “call karan” as input, while debugging the

How to compare two string dates in Java?

I have two dates in String format like below – I want to make sure startDate should be less than endDate. startDate should not be greater than endDate. How can I compare these two dates and return boolean accordingly? Answer Convert them to an actual Date object, then call before. Recall that parse will throw a ParseException, so you should

String.valueOf(Integer) always return 1

I’m trying to parse String “2 2 2” and add every symbol ‘2’ in ArrayList. This is my code: I can’t understand why System.out.println(String.valueOf(myIntArray.get(rawSize)));always return 1 ? UPDDATE: I try read file, which contain next text: Here is my Main function: public static void main(String[] args){ My output: When i replace:a_char = line.charAt(charCounter); with a_char = ‘5’;, my output: Can’t

Advertisement