I just started today with Java. The thing is as follows:
From class Notes in my class I have this properties and methods
import java.util.*; public class Notes { //properties ArrayList<String[]> notes; //constructor public Notes() { // TODO Auto-generated constructor stub notes = new ArrayList<String[]>(); //notes = new HashSet<String>(); } //Adds a new note public void set(String title, String body, String location) { String note[] = {title, body, location}; notes.add(note); } //Retrieves all notes public ArrayList get() { return notes; } //Deletes a note public boolean del() { return true; }
I am trying to catch the message sent from Notes in line 11 from the Main class
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { Notes notes = new Notes(); notes.set("User 1", "This is a voicemail message for Jonathan", "World wide web"); //line 11 where I'm trying to catch the message sent from Notes ArrayList<String> allNotes = notes.get(); for (String i: allNotes) { System.out.println(notes.get()); } } }
And the code doesn't show any syntax error so far. When I run the code the console throws the next
Exception in thread "main" java.lang.ClassCastException: class [Ljava.lang.String; cannot be cast to class java.lang.String ([Ljava.lang.String; and java.lang.String are in module java.base of loader 'bootstrap') at Main.main(Main.java:13)
What I am doing wrong? any help to learn to catch the Set and print it out please?