Created
June 19, 2014 06:58
-
-
Save yomusu/fb35989b889fb10495d4 to your computer and use it in GitHub Desktop.
join iterable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Hoge { | |
/*** | |
* | |
* sepaで連結して文字列を作成します | |
* | |
* @param sepa | |
* @return | |
*/ | |
static public String join( Iterable iterable, String sepa ) { | |
Iterator it = iterable.iterator(); | |
if( it.hasNext() ) { | |
StringBuilder buf = new StringBuilder(); | |
buf.append( itemToString(it.next()) ); | |
while( it.hasNext() ) { | |
buf.append(sepa); | |
buf.append( itemToString(it.next()) ); | |
} | |
return buf.toString(); | |
} else { | |
// nothing | |
return ""; | |
} | |
} | |
/** 項目をString化するヤツ(本当はdelegateぽくしたい) */ | |
static protected String itemToString( Object obj ) { | |
if( obj !=null ) { | |
return obj.toString(); | |
} | |
return ""; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment