I wrote this program to read the input from the scanner and store it as an object using ArrayList. However, it didn't print the correct content when I tested it. Like I input: Apple Pie, the output is Words@4aa298b7, Words@7d4991ad.
Am I missing sth? here is my code:
import java.util.ArrayList;
import java.util.Scanner;
public class W7E2 {
public static void main(String[]args) {
System.out.println("Please anter words: ");
Scanner sc = new Scanner(System.in);
String []w = sc.nextLine().split(" ");
ArrayList<Words> word = new ArrayList<Words>();
for(int i = 0; i < w.length; i++) {
word.add(new Words(w[i]));
}
System.out.println(word);
}
}
class Words {
private String wor;
public Words(String wor) {
this.wor = wor;
}
}