user2192658
user2192658

Reputation: 41

Loading data, data to array, array to JList

public static void load() {
    try {
        URL load = new URL("http://www.site.net/loader.php?username=" + "username" + "&password=" + "password");
        BufferedReader in = new BufferedReader(
                new InputStreamReader(load.openStream()));

                String inputLine;
                while ((inputLine = in.readLine()) != null){
                    if(inputLine.length() > 0){
                        put = inputLine;
                        put.split(":");
                        System.out.print(put);

                    }
                }
    } catch (IOException e){
        e.printStackTrace();
    }
}

As you see there, I'm trying to split the following data:

Image

How do I remove the quotations and store it in an array, so I can load it up in an JList?

Put = String put;

Upvotes: 0

Views: 629

Answers (1)

Roddy of the Frozen Peas
Roddy of the Frozen Peas

Reputation: 15180

The String split method returns a String array. It does not change the original string, so this line does nothing:

put.split(":");

Instead, consider something like this. First split at the colon:

String[] parts = put.split(":");

Then for each part, remove the quotations:

for( int i = 0; i < parts.length; i++) {
    parts[i] = parts[i].replaceAll("\"", "");
}

Then use the array of cleaned up strings to back a JList:

JList myList = new JList(parts);

Upvotes: 1

Related Questions