convert list to charsequence

sir i have a list :that contain some value : after i am geeting node content value: and cheak that node content value contains list value or not:but i am getting exception because list not converted to charsequence : my code is List<String> xx = new ArrayList<String>(); xx.add("Van"); xx.add("Von"); xx.add("Le"); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document d = builder.parse(file); d.getDocumentElement().normalize(); String[] s = xx.toArray(new String[xx.size()]); NodeList ndlist = d.getElementsByTagName("personName"); for (int i = 0; i < ndlist.getLength(); i++) { Node node = ndlist.item(i); NodeList nl = node.getChildNodes(); for (int j = 0; j < nl.getLength(); j++) { Node node1 = nl.item(j); if (node1.getNodeName().equals("givenNames")) { Element element = (Element) node1; String str = element.getTextContent().toUpperCase(); if(str.contains(xx))//error list cannot convert to charsequence { //some opration } } }
sanjeev kumarAsked:
Who is Participating?
 
CEHJConnect With a Mentor Commented:
String[] s = xx.toArray(new String[xx.size()]);//casting list to String

Open in new window

That's unnecessary. You just need to iterate 'xx'

for (String s : xx) {
   if(str.contains(s.toUpperCase())) {
      // Do something
   }
}

Open in new window


Can you explain the presence of the question HERE?
0
 
CEHJConnect With a Mentor Commented:
... my code is ...
Post code in code tags please, and not in bold
0
 
sanjeev kumarAuthor Commented:
Thank u CEHJ
List<String> xx = new ArrayList<String>(); xx.add("Van"); xx.add("Von"); xx.add("Le"); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document d = builder.parse(file); d.getDocumentElement().normalize(); String[] s = xx.toArray(new String[xx.size()]); NodeList ndlist = d.getElementsByTagName("personName"); for (int i = 0; i < ndlist.getLength(); i++) { Node node = ndlist.item(i); NodeList nl = node.getChildNodes(); for (int j = 0; j < nl.getLength(); j++) { Node node1 = nl.item(j); if (node1.getNodeName().equals("givenNames")) { Element element = (Element) node1; String str = element.getTextContent().toUpperCase(); if(str.contains(xx))//error list cannot convert to charsequence { //some opration } } }

Open in new window

0
 
sanjeev kumarAuthor Commented:
List<String> xx = new ArrayList<String>();
 xx.add("Van"); 
xx.add("Von");
 xx.add("Le");
 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
 DocumentBuilder builder = factory.newDocumentBuilder();
 Document d = builder.parse(file); 
d.getDocumentElement().normalize(); 
String[] s = xx.toArray(new String[xx.size()]);//casting list to String
 NodeList ndlist = d.getElementsByTagName("personName");
 for (int i = 0; i < ndlist.getLength(); i++)
 { 
Node node = ndlist.item(i); 
NodeList nl = node.getChildNodes(); 
for (int j = 0; j < nl.getLength(); j++) 
{ 
Node node1 = nl.item(j);
 if (node1.getNodeName().equals("givenNames"))
 {
 Element element = (Element) node1;
 String str = element.getTextContent().toUpperCase(); 
if(str.contains(xx))//error list cannot convert to charsequence
 { 
//some opration
 } } }

Open in new window

0
 
sanjeev kumarAuthor Commented:
Thanks for your comment
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.