problems with java toLowerCase function when using arrays and multiple 'words' in the string

I am exceptionally new to java, as in, I can barely write 20 lines of basic code and have them work, level of new, I have 2 issues which may or may not be related as they are from very similar pieces of code that I have personally written.

import java.util.Scanner;

public class StringCW {


public static void main (String [] args) {

    String word = ""; 

    while(!(word.equals("stop"))){


        Scanner capconversion = new Scanner(System.in);
        System.out.println("Enter word:" );

        word = capconversion.next(); 
        String lower = word.toLowerCase();
        word = lower;
        System.out.println("conversion = " + word);

    }


    System.out.println("ending program");


        }
    }
}

This is my first chunk of code, it is designed to take any string and convert it into lowercase, however if I am to print anything seperated by a space, eg: "WEWEFRDWSRGdfgdfg DFGDFGDFG" only the first 'word' will be printed and converted, I am also getting a memory leak from cap conversion, though I don't understand what that means or how to fix it

My second problem is likely along the same lines

import java.util.Scanner;

public class splitstring {

private static Scanner capconversion;

public static void main (String [] args) {

    String word = ""; 

    while(!(word.equals("stop"))){

        capconversion = new Scanner(System.in);
        System.out.println("Enter word:" );

        word = capconversion.next(); 
        String lower = word.toLowerCase();
        String[] parts = lower.split(" ");
        parts [0] = "";
        parts [1] = "";
        parts [2] = "";
        parts [3] = "";
        parts [4] = "";


        System.out.println("conversion = " + lower
        parts [0] + parts [1] + parts [2] + parts [3] + parts [4]);

        }

        System.out.println("ending program");
    }
}

this is the 2nd chunk of code and is designed to do the same job as the previous one except print out each 'word' on a new line, then return to the input part until the stop command is entered

the error I get is

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
    at splitstring.main(splitstring.java:21)

however I don't understand where the error is coming in

Jon Skeet
people
quotationmark

This is because you're using Scanner.next(), which returns a single token - and which uses whitespace as a token separator by default.

Perhaps you should use nextLine() instead, if you want to capture a whole line at a time?

As for your ArrayIndexOutOfBoundsException - that has basically the same cause. You're calling split on a single word, so the array returned has only one element (element 0). When you try to set element 1, that's outside the bounds of the array, hence the exception.

Note that nothing in here really has anything to do with toLowerCase().

people

See more on this question at Stackoverflow