DEV Community

Cover image for πŸš€ Shared Preferences API for Java πŸš€
omega ui
omega ui

Posted on β€’ Edited on

1

πŸš€ Shared Preferences API for Java πŸš€

Hello, world!
This tiny API is worth taking a look.

Features

  • πŸ“’ No Redundancy
  • 😼 Easily Handles multiple references of same Storage
  • πŸ€– Real-Time Write i.e Automatically Saves file on changes
  • πŸŽ‰ Auto constructs the entire path
  • πŸš€ Usable with Java CLI and any GUI framework

Example:


public class Preferences {
    public static void save(){
        HashMap<String, Integer> map = new HashMap<>();
        map.put("Simon", 99);
        map.put("Alex", 96);
        map.put("Sofia", 89);

        DataStorage storage = DataStorage.getStorage(".config", "settings.json");
        storage.put("students", map); // Auto-Save

        System.out.println(storage.query("students", "Simon"));
        // Displays 99


        DataStorage storage2 = DataStorage.getStorage(".config", "settings.json");
        storage2.put("teachers", 18); // Auto-Save
        // storage2 is the same storage object with no object redundancy 😎

    }

    public static void main(String[] args) {
        save();
    }
}

Enter fullscreen mode Exit fullscreen mode

Visit Repo

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

πŸ‘‹ Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Communityβ€”every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple β€œthank you” goes a long wayβ€”express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay