Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Scala'da Döngü İfadeleri Yazımdaki Örnek 4
// Java
String[] isimler = new String[] {"Ali", "Veli", "Ahmet", "Hüseyin", "Akif"};
String[] secilenIsimler = new String[isimler.length];
int i = 0;
for (String isim : isimler) {
if (isim.startsWith("A") && isim.length > 3) {
System.out.println("Seçilen isim: " + isim);
secilenİsimler[i] = isim;
i++;
}
}
// Scala
val isimler: Array[String] = Array("Ali", "Veli", "Ahmet", "Hüseyin", "Akif")
val secilenIsimler: Array[String] = for (isim <- isimler if isim.startsWith("A") && isim.length > 3) yield {
println("Seçilen isim: " + isim)
isim
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.