[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

String Buffer - logic

Posted on 2011-10-10
11
Medium Priority
?
268 Views
Last Modified: 2012-05-12
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) {

}
0
Comment
Question by:jkteater
  • 8
  • 2
11 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 36944104
it is checking if there is string "SORT" insiide thrreeS
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36944107
But here SORT should be eithert in quotes or it is another string variable name?
ThreeDName = SORT
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36944121
In general method s0.indexOf(String s) will determine want is the charcater niumber shere String s starts  within
string or stringbuffer s0
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 47

Expert Comment

by:for_yan
ID: 36944135
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
 
LVL 47

Expert Comment

by:for_yan
ID: 36944151
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
 
LVL 47

Accepted Solution

by:
for_yan earned 200 total points
ID: 36944171
so in your case if threeS does not contain SORT it will get inside the braces, otherwise it will skip it
0
 

Author Comment

by:jkteater
ID: 36944174
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 36944199
>>
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 36944204
(sorting or comparing really)
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36944206
It will not allow to get inside  braces  of your StringBuffer contains SORT or is equal to SORT
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36944321
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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses
Course of the Month19 days, 13 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question