1
I have several strings in one ArrayList
. I would like to know how to return a string from that list that contains another one that was passed. For example, if I pass one String
"Bean"
, want to return the string "AtendenteBean"
.
1
I have several strings in one ArrayList
. I would like to know how to return a string from that list that contains another one that was passed. For example, if I pass one String
"Bean"
, want to return the string "AtendenteBean"
.
5
Whereas you’re wearing one ArrayList
to store their String
s I would advise you to go through all the variables in your list and check if it contains the desired text. Example:
List<String> list = new ArrayList<String>();
//pega os dados do xhtml e joga na variavel list
for(String s: list) {
if(s.contains("Bean")) {
System.out.println(s);
}
}
In the above example I am printing all the String
s that have the literal Bean
of the variable list
and then printing it. Instead of printing you can manipulate the variable s
as you wish, it contains the excerpt from the literal that you put on probation if
above.
1
I think you’re confusing what a "String" is. Don’t you mean an Atendentebean class, which for example you inherit from Pessoabean? If you are sure that an instance of Pesoabean is an Attendant, you can use a cast, see if the example below makes sense:
PessoaBean p = findPessoa(...);
if (p instanceof AtendenteBean) }
String codAtendente = ((AtendenteBean) p).getCodAtendente();
}
i am not confusing, just want to pick up a text that is inside a page, passing a part of this text.
1
I managed using regex
.
Pattern pattern = Pattern.compile("\\{(.+?)Bean");
Matcher matcher = pattern.matcher(text);
while (matcher.find()){
beanName = matcher.group(1);
beanName = beanName.concat("Bean");
if (text.contains(beanName)) {
break;
}
}
He searches for words that contain Bean
and start with the key {
. If the text contains, it breaks the loop.
0
Man, try to elaborate on your question, I couldn’t understand exactly what you meant.
Anyway, it seems to me that what you want is something like objeto.getClass().getSimpleName()
.
really missed me putting that Bean
is a part of a string
Browser other questions tagged java string
You are not signed in. Login or sign up in order to post.
Dude, it’s still really messed up. What exactly can come of this
String
Bean
? What kind of code do you expect in response? What is the format of thisxhtml
? BesidesAtendenteBean
, what else isString
could it be? You have a classAtendenteBean
? If yes, how is this class?– Victor Stafusa
Dude, I want this, I’m gonna pass a piece of a
String
,Bean
for example, and returns meAtendenteBean
. I extract the text from inside the pagexhtml
. It would be like a search insql
using like`.– Macario1983
Eu extraio o texto de dentro da página xhtml
, extract and store where in your code? An array, an Arraylist? Maybe you should leave that part of xhtml aside in your question, since that information doesn’t seem relevant to anyone giving the answer you need– Math
@Math I store in a structure with
ArrayList
– Macario1983
Look, the String class has the method contains(). As far as I understand, this is what you want...http://docs.oracle.com/javase/6/docs/api/java/lang/String.html#contains%28java.lang.Charsequence%29
– Edgar Muniz Berlinck
Okay, it’s going to be really big, but it’s okay. Imagine that this is a
String
.Este texto contem algumas palavras de dúvida de alguém que queira saber pelos usuários do stackOverflow como resolver sua dúvida
. And there, I want for example to pass theString
life, and return me the worddúvida
. They understood?– Macario1983