write a program to use valueOf and compareTo method in Java 8?

The compareTo() method are compares two strings lexicographically.
Integer::valueOf  it is an inbuilt method which return an integer object.

				
					import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

@FunctionalInterface
interface Converter<F, T> {
	T convert(F from);
}

public class A {
	public static void main(String[] args) {
		Converter<String, Integer> d = Integer::valueOf;
		Integer c1 = d.convert("123");
		System.out.println("convert String to Integer:- " + c1);
		List<String> list = Arrays.asList("we", "rt", "yui");
		Collections.sort(list, new Comparator<String>() {
			public int compare(String a, String b) {
				return a.compareTo(b);
			}
		});
		System.out.println("from comparator:- " + list);
		Collections.sort(list, (String h1, String h2) -> {
			return h1.compareTo(h2);
		});
		System.out.println("from java8 sorting:- " + list);
	}
}
				
			

Output :-
convert String to Integer:- 123
from comparator:- [rt, we, yui]
from java8 sorting:- [rt, we, yui]

write a program to use valueOf and compareTo method in Java 8? Read More »