JavaSnips

From Custard
Jump to: navigation, search

Contents

Java Snippets

when(textStoryBuilder.build()).thenReturn( new ArrayList(){{add(textStoryItem);}} );


Iterators

Collection Iterator

Collection<String> nameCollection = new ArrayList<String>();
for( Iterator<String> iterator = nameCollection.iterator(); iterator.hasNext();){
    String value = iterator.next();
    iterator.remove();  // It's possible to remove items from the collection
}

List ForEach

List<String> nameList = new ArrayList<String>();
for ( String name : nameList ){
      System.out.println( name );
}

Map ForEach

Map configMap = new HashMap<String, String>();    
for( Entry entry: configMap.entrySet() ) {        
    String key   = entry.getKey();
    String value = entry.getValue();
}    
Personal tools