• Post Reply Bookmark Topic Watch Topic
  • New Topic

Crate an Immutable List?  RSS feed

 
Kaustubh G Sharma
Ranch Hand
Posts: 1283
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to Crate an Immutable List??
 
Claudiu Chelemen
Ranch Hand
Posts: 75
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please take a look at

http://download.oracle.com/javase/6/docs/api/java/util/Collections.html?is-external=true#unmodifiableList(java.util.List)

However, it creates an immutable list from an already existing mutable one. Hope it helps.

Cheers!
 
Kaustubh G Sharma
Ranch Hand
Posts: 1283
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Claudiu Chelemen wrote:Please take a look at

http://download.oracle.com/javase/6/docs/api/java/util/Collections.html?is-external=true#unmodifiableList(java.util.List)

However, it creates an immutable list from an already existing mutable one. Hope it helps.

Cheers!


Thanks Claudiu
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not actually an immutable list. It is a read-only view of a List which may change while you are viewing it.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16059
88
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java doesn't have any really immutable list data structure in its standard library. At work I'm using Google Guava, a handy library from Google, that does have really immutable data structures.
 
Pat Farrell
Rancher
Posts: 4686
7
Linux Mac OS X VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I second the recommendation of Google Guava's Immutable collections. They are fast, work consistently. Free and open source code, etc.
 
Kaustubh G Sharma
Ranch Hand
Posts: 1283
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pat Farrell wrote:I second the recommendation of Google Guava's Immutable collections. They are fast, work consistently. Free and open source code, etc.


How can i use it?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
 
Kaustubh G Sharma
Ranch Hand
Posts: 1283
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David O'Meara wrote:http://code.google.com/p/guava-libraries/


Thanks DAVID
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try something like
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If only there were a way to embed that link into the text when Google Guava was first mentioned in this thread. That would have been very helpful.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike Simmons wrote:If only there were a way to embed that link into the text when Google Guava was first mentioned in this thread. That would have been very helpful.

auto links like IOException could be done for any library but in practice we limit to the code JSE and JEE classes.
There is another explicit link which includes a large number of libraries and I have just added Google Guava to it to be added to the next release.
Once in [javadoc]com.google.common.collect.ImmutableList[/javadoc] will link directly to their API.
eg org.apache.commons.jxpath.JXPathContext
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, let me rephrase: If only Jesper had thought to put in such a link back when he first mentioned Google Guava in this thread.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that too. The ability to use a search engine would be useful too.
 
Kaustubh G Sharma
Ranch Hand
Posts: 1283
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David O'Meara wrote:that too. The ability to use a search engine would be useful too.


Aye Aye Sir
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!