Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.math.BigDecimal;
- import java.math.BigInteger;
- import java.text.DecimalFormat;
- import java.util.*;
- import java.util.stream.Collectors;
- public class CheatSheet {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String[] array = new String[2];
- Collections.reverse(Arrays.asList(array));
- Arrays.sort(array); // Sorts arr[] in ascending order
- System.out.println("Modified arr[] : " + Arrays.toString(array));
- Arrays.sort(array, Collections.reverseOrder()); // Sorts arr[] in descending order
- System.out.print(array.toString().replace("[", "").replace("]", "")
- .trim().replaceAll(",", "").replaceAll("\\s+", " "));
- int[] arr = new int[2];
- int number = Integer.parseInt(Arrays.toString(arr).replaceAll("[\\[\\], ]", ""));
- List<Integer> list = new ArrayList<Integer>();
- Collections.sort(list);
- Collections.sort(list, Collections.reverseOrder());
- System.out.println(list.stream().map(String::valueOf).collect(Collectors.joining(" ")));
- System.out.println(String.join(" ", list.stream().map(String::valueOf).collect(Collectors.toList())));
- System.out.println(list.toString().replaceAll("[\\[\\],]", ""));
- System.out.println(String.join(System.lineSeparator(), array));
- int one = 1;
- System.out.printf("%03d", one); /// 001
- double n = Double.parseDouble(scanner.nextLine());
- System.out.print(new DecimalFormat("0.####").format(n)+ " ");
- //0003.147896325
- DecimalFormat decimalFormat = new DecimalFormat("#0.00");
- DecimalFormat decFormat = new DecimalFormat("#.#####");
- DecimalFormat deciFormat = new DecimalFormat("##.00");
- DecimalFormat result1 = new DecimalFormat("0.##");
- Map<String, List<Integer>> companyList = new LinkedHashMap<>();
- companyList.entrySet().stream().forEach(company -> {System.out.println(company.getKey());
- company.getValue().forEach(employee -> System.out.println("-- " + employee));});
- Map<String, Integer> mapList = new LinkedHashMap<>();
- mapList.entrySet().forEach(entry -> System.out.println(entry.getKey() + ": " + entry.getValue()));
- Map<String, Integer> topThree =
- mapList.entrySet().stream()
- .sorted(Map.Entry.comparingByValue(Comparator.reverseOrder()))
- .limit(3)
- .collect(Collectors.toMap(
- Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
- // bestCandidate.entrySet().stream().sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())).limit(1)
- // .forEach(entry -> System.out.printf("Best candidate is %s with total %d points.\n", entry.getKey(), entry.getValue()));
- List<String> sortedPlayers = new ArrayList<>();
- mapList.entrySet().stream().sorted(Map.Entry.comparingByValue()).forEach(a -> sortedPlayers.add(a.getKey()));
- Collections.reverse(sortedPlayers);
- List<StringBuilder> SBlist = new ArrayList<>();
- Collections.sort(SBlist, new Comparator<StringBuilder>() {
- @Override
- public int compare(StringBuilder o1, StringBuilder o2) {
- return (o1).compareTo(o2);
- }
- });
- // String output = arraylist. toString(). replaceAll(“(^\\[|\\]$)”, “”);
- // first we are removing first square bracket then we are removing the second square bracket
- // and replacing i with empty string.
- int m = Integer.parseInt(scanner.nextLine());
- BigInteger bigInt = new BigInteger(String.valueOf(1));
- // при m = 5, String.valueOf(m) и в multiply String.valueOf(6) result 5 * 6(на 6-та)
- for (int i = 1; i <= m ; i++) {
- bigInt = bigInt.multiply(BigInteger.valueOf(Integer.parseInt(String.valueOf(i))));
- }
- // bigInt = bigInt.multiply(BigInteger.valueOf(Integer.parseInt(String.valueOf(6)))); 6 на степен m
- BigDecimal sum = new BigDecimal("0");
- String num = scanner.nextLine();
- BigDecimal bdNUm = new BigDecimal(num);
- sum = sum.add(bdNUm);
- // employeeList.sort(Comparator.comparing(CompanyRoster.Employee::getSalary).reversed());
- // peopleList.sort(Comparator.comparing(OrderByAge.People::getAge));
- // System.out.println(team.getUser().stream().collect(Collectors.joining(System.lineSeparator())));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement