String Buffer - logic

Can someone explain to me what this statement is really doing?

threeS is a String Buffer and lets say that
ThreeDName = SORT

if (threeS.indexOf(ThreeDName) == -1) {

}
jkteaterAsked:
Who is Participating?
 
for_yanConnect With a Mentor Commented:
so in your case if threeS does not contain SORT it will get inside the braces, otherwise it will skip it
0
 
for_yanCommented:
it is checking if there is string "SORT" insiide thrreeS
0
 
for_yanCommented:
But here SORT should be eithert in quotes or it is another string variable name?
ThreeDName = SORT
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
for_yanCommented:
In general method s0.indexOf(String s) will determine want is the charcater niumber shere String s starts  within
string or stringbuffer s0
0
 
for_yanCommented:
if this method does not find any occurrences of s within s0 it will return -1
So if it returns something > -1 it means that there is occurence of string s within s0
0
 
for_yanCommented:
For exmple if your StringBuffere contains "mother and father"
then

StringBuffer sb = new StringBufferr("mother and father");
then sb.indexOf("mother") will return 0

but

sd.indexOf("sister") will return -1

0
 
jkteaterAuthor Commented:
the reason I am asking is because that IF statement is in a for loop and works as long as the ThreeDName is not the same, if ThreeDName is the same, it never goes in to the IF

Does that make since

Basically my For loop is getting a array of names, each name as a option and a value, so it would be something like

ThreeDName = SORT
Option = sort_list
value = 199

so there can be the same ThreeDName SORT with different options and value.  But it seems like that IF statement will not allow in a second SORT
0
 
CEHJCommented:
>>
so there can be the same ThreeDName SORT with different options and value.  But it seems like that IF statement will not allow in a second SORT
>>

Sounds like you should be sorting an array or collection of objects having those three fields
0
 
CEHJCommented:
(sorting or comparing really)
0
 
for_yanCommented:
It will not allow to get inside  braces  of your StringBuffer contains SORT or is equal to SORT
0
 
for_yanCommented:
Maybe you want to post more of your code if you feel something is not clear in the broader sense,
as I farnkly did not fully understand the full picture of what you are doing,
 but I hope  the meaning of indexOf() method is understandable
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.