I have recently started using java 7 and I want to use <> diamond operator in my existing code. Can anyone tell how to find and replace all the instances of ArrayList to ArrayList<>.
For e.g.:
List<Integer> list = new ArrayList<Integer>();
would become
List<Integer> list = new ArrayList<>();
I can follow same patter for Set and Map,too.
Looking for
([^\t (](List|Map|Set))<[^>]+>(Case sensitive + Regular expression) and replacing by$1<>(Regular expression) worked for me.Regex:
([^\t (](List|Map|Set)): any char but a space, a tab or an opening parenthese, followed by List, Map or Set (to match any kind of collections)ArrayListwill match (i.e.yList)LinkedListtoo (i.e.dList)Listwon’t (there’s no char before List)<[^>]+>: starts with<, then any char but>1 time or more, then>$1<>: chars that were between the surrounding parentheses followed by<>How to:
1) Ctrl + H
2)
3)