문제

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

도움이 되었습니까?

해결책

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");

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top