How to create a unmodifiable/read-only list in Java?

Discussion in 'Computer Questions, Issues & Security' started by jamesmercer, Jun 26, 2014.

  1. jamesmercer

    jamesmercer
    uix_expand uix_collapse
    New Member

    Joined:
    Jun 26, 2014
    Messages:
    1
    Likes Received:
    0
    Hi My name is James iam a java fresher please let me know How to create a unmodifiable/read-only list
    in Java?
     
  2. adaltonreis

    adaltonreis
    uix_expand uix_collapse
    New Member

    Joined:
    Mar 11, 2015
    Messages:
    4
    Likes Received:
    1
    Hi, Jamesmercer !

    How did you solved the situation?

    There is a simple way to do this by using the clone method. By this way the method that returns your list will not return the proper list instead, will return only copy of them.

    This prevent your list to be modified.
     

Share This Page