Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
LambdaExpression
//'main' method must be in a class 'Rextester'. //Compiler version 1.8.0_111 import java.util.*; import java.lang.*; class Rextester { static String StringOp(StringFunc sf,String s){ return sf.func(s); } public static void main(String args[]) { String inStr = "Lambdas add power to Java programming"; String outStr; System.out.println("Here is input string: "+inStr); outStr = StringOp((str) -> str.toUpperCase(), inStr); //This passes a block lambda that removes spaces. outStr = StringOp((str) -> { String result = ""; int i; for(i=0; i<str.length(); i++){ if(str.charAt(i) != ' ') result += str.charAt(i); } return result;}, inStr); StringFunc sf = (str) -> { String result = ""; for(int i=str.length()-1; i>=0; i--){ result +=str.charAt(i); } return result; }; System.out.println(StringOp(sf,inStr)); } } interface StringFunc{ String func(String n); }
run
|
edit
|
history
|
help
0
extends
Meena
Abhay
mango
queue_using_stack
상속1
Add Index of max number in an array
susun
Problem: binary
some string reverse in java