TAGS :Viewed: 8 - Published at: a few seconds ago

[ How can I getText for the first element of my String method? ]

I have a String Split() containing two strings: one and two. I add it to a Linked list. Now I need to get the first element of one.

String split() {
one = ""; 
two = "";       
int index = tableFields.indexOf("(");
        if (index > -1){
        one = tableFields.substring(0, index);
        two = tableFields.substring(index + 1,
                tableFields.length() - 1);

        return "`" + one + "`" + " "+  two;
        }
        else {
            return "";
        }

}


void readTextFile() {

    String line;

    while (FileReaderScanner.hasNextLine()) {
    fieldlist.add(split());  }   

}

Answer 1


try this:

String yourString = Split();
int startIndex = yourString.indexOf("`") + 1;
int endIndex = yourString.indexOf("`", startIndex);
String result = yourString.substring(startIndex, endIndex);