-
-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
There is a bug when i set the list #61
Comments
This is not a bug. You are creating an ArrayList that is not of <Strings>, but of <Object>!
Now, the myWrongList contains 4 elements, and not 6 elements. To fix your problem, rather than calling add(anotherList) you should be calling addAll Code showing how to reproduce your problem.
|
As stated, that is the intended behaviour. Thank you @EverNife for the answer. With Example to add elements to a list: // Create the YamlFile
YamlFile config = new YamlFile("examples/test61.yml");
// Create a new config file if it does not exist or load its contents otherwise
config.createOrLoad();
// Set the list
config.set("key", new ArrayList<>(Arrays.asList("oldElement1", "oldElement2")));
// Get the previously set list (copy)
List<String> list = config.getStringList("key");
// Add several elements to the list
list.addAll(Arrays.asList("newElement1", "newElement2"));
// Add single element to the list
list.add("newElement3");
// Update the list elements
config.set("key", list);
// You can also add elements with list indexing!
config.set("key[-1]", "lastElement");
// Save the configuration file
config.save(); key:
- oldElement1
- oldElement2
- newElement1
- newElement2
- newElement3
- lastElement |
so basically I used the library for a few days, and I found out that when I have a list already and try to add an element to it, something weird happens, so I create the List first by using
config.set("key", ArrayList<String>(""))
so first I want to create empty list.but in the YML file it's not empty, so the bug is when I try to add an element like this:
it displayed in the file like this
it's so weird bug...
The text was updated successfully, but these errors were encountered: