title: input data in an arraylist without using an array in java
body: <p>i am not very good in java and i am trying to make my codes better.i am trying 
    to enter a sentence then split the sentence into word and then store the words 
    in an arraylist.Afterwards i have to enter a word and check if the word is 
    found into the sentence.So far i have managed to do and the codes work.however 
    i want to do it without using an array since i dont ever use the array 
    afterwards,so it is kind of redundant.Is there a way so as i may enter the 
    words in an arraylist directly without using an array?</p>
  
  <pre><code>  here are my codes:
     public static void main(String[] args){
      //the user is asked to enter a sentence
       Scanner input=new Scanner(System.in);
       System.out.println("enter a sentence");
          String text=input.nextLine();
  
          //the sentence is split
          String[] s=text.split("[[\\s+]*|[,]*|[\\.]]");
  
           ArrayList&lt;String&gt; list=new ArrayList&lt;String&gt;();
            //the word are stored into a variable then added into the array
              for(String ss:s){
                  list.add(ss);
                  }
  
            System.out.println("enter a word");
            String word=input.next();
              //check if the word is in the arraylist
             for(int i=0;i&lt;list.size();i++){
              if(word.equals(list.get(i))){
                System.out.println("the word is found in the sentence");
                    System.exit(0);
            }
  
          }
          System.out.println("the word is not found in the sentence");
  
        }
  </code></pre>