Search code examples
javastringnetbeans-platform

Turning wsdl result into a multiple line list


In my programming class we have been assigned a task to get results from a wsdl and seperate the results into a list. For example,

children & family;children;family;friends

The task is to seperate the line at every ";" and input the information on the next line, so it transforms from a line into a list, such as..

children & family
children
family
friends

How do I got about doing this? I've been stuck for quite awhile.

This is all in Java by the way


Solution

  • Say String wsdlString would be what you get as input and the result of your method should be a ArrayList<String>:

    public ArrayList<String> seperateIntoList(String wsdlString){
          String[] resultArray =  wsdlString.split(";");
          ArrayList<String> resultList = new ArrayList<String>(resultArray.size());
    
          for(String listItem: resultArray) {
              resultList.add(listItem);
          }
    
          return resultList;
    }
    

    I wasn't quite sure, but if you only want a String with linebreaks instead of a List you can just use wsdlString.replace(";","\n");