Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
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.
Closed 9 years ago.
Improve this question
I have some specific task. We have String like "(()[]<>)" or something familiar with this.
A question in my interview qustion was how check either String is correct or incorrect.
For example: "()[]<>" - true, "([)" - false, "[(])" - false, "([<>])" - true.
Thank you guys very much!
You would need to use a stack to process this.
When you find a new opening parenthesis you would push onto the stack.
When you find a closing parenthesis, peek at the top element on the stack - and see if it matches. I.e. if you've just found a ")", was the last element on the stack a "("?
If it was, then pop that element of the stack. If it wasn't then you've got an "incorrect" String and you can stop processing any further.
Also, once you get to the end of the string, if there's anything left on the stack we know there's an non-terminated parenthesis.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have array list that each indexes has value either 0 or 1.I want to find that continuously three indexes has the value 1.How do I find it?
Without actual code:
iterate thorough the array
count the 1s you found
if you found a 0 then start over the count
check after increasing the counter: if the counter reaches 3 then return with true
if you reached the end of the array and no more elements then return with false
Something like this, I hope I could help.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I am trying below:
I am trying to process where condition of sql in java. How can I get column name in where condition as a string ?
Ex: String s = "Name_id>=11"
now I want to get "Name_id", as it is a column name and i want to do processing on it.
I know it can be done using regex but I am new to regex and don't know how to do it. can someone guide me??
help will be appreciated, thanks
You can try this
s = s.replaceAll("^(\\w+).+", "$1");
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 array
String[] albumnames;
now how to take a string from particular index position with limited number of charachters.
For example,
if, albumnames[position] have value "abcdefghijk"
then i want to take the first 5 characters only.
That is "abcde".
The substring method of String can be used to achieve this. Try
String s = albumnames[position].substring(0,5);
See substring docs
albumnames[position].substring(0,5);
you can see the methods in String class, like substring, indexof
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
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.
Closed 9 years ago.
Improve this question
I'm having some problems with understanding how regular expressions work.
I am using Autolocation with Tasker on my android and have marked 2 types of locations with the patterns
[Safe] theNameOfTheSafePlace
and
[Danger] theNameOfTheDanger
I am trying to find out if the area I'm in is marked as safe or dangerous. I have tried using regex with the name
/[Safe/](.+)
but it doesn't recognize it.
What am I doing wrong and what would be the correct way to write this expression?
Thanks
You should be using backslashes \ to escape the [] not forward slashes.
Try:
\[safe\](.+)
Should be "\[Safe\](.+)" instead of "/[Safe/](.+)" ?
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
What I am looking to do is split a given string in Java using a tab delimiter. After the seventh split, I would like to keep everything after that point as an eighth split. This last split will contain tabs also, but must remain intact.
Use the split method that takes two parameters, the second being the split limit. You can pass in a limit of 8. The eighth element will contain the rest of the string after the seventh split.