Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *
- * @author Pudding
- */
- public class Test {
- static class BeanUsers {
- private String userID;
- public BeanUsers() {
- this("");
- }
- public BeanUsers(String userID) {
- this.userID = userID;
- }
- public String getUserID() {
- return userID;
- }
- }
- public static class FileHandler {
- private FileHandler() {
- } //Konstruktor
- private ArrayList<BeanUsers> allUser = new ArrayList<>();
- private static FileHandler instance = null;
- private BeanUsers currentUser = new BeanUsers();
- public static synchronized FileHandler getInstance() {
- if (instance == null) {
- instance = new FileHandler();
- }
- return instance;
- }
- public int addNewUser(BeanUsers neuer) {
- this.allUser.add(neuer); //hier soll es eigentlich nur ANGEHANGEN werden
- return this.allUser.indexOf(neuer); //gibt index, des neuen Elementes zurück
- }
- public ArrayList<BeanUsers> getAllUser() {
- return allUser;
- }
- }
- public static void main(String[] args) {
- FileHandler handler = FileHandler.getInstance();
- System.out.println(handler.addNewUser(new BeanUsers("Pudding")));
- System.out.println(handler.addNewUser(new BeanUsers("Pudding2")));
- for (BeanUsers user : handler.getAllUser()) {
- System.out.println(user.getUserID());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement