Find Count Of Each Element from Array | Java Interview Questions and Answers

Поделиться
HTML-код
  • Опубликовано: 18 окт 2024

Комментарии • 14

  • @revathir1995
    @revathir1995 2 года назад +2

    Static varibales cannot be declared inside methods or members of a class

  • @rads1436
    @rads1436 5 месяцев назад

    may i know y the count of 10 is again printing as 2 so we neeed to set the value to -1 if the number is going to repeat again

  • @satishbhutawale4226
    @satishbhutawale4226 7 месяцев назад +1

    package com.method;
    public class FrequencyOfElements
    {
    public static void main(String[] args)
    {
    int[] arr= {10,20,30,10,30,40,50,50,50,60};
    int[] count=new int[256];

    for(int i=0;i

  • @shivask1751
    @shivask1751 2 года назад

    Remove static for y, you'll get output as 1

  • @bheemarayaa9507
    @bheemarayaa9507 2 года назад

    static variable can't be declared in funtion scope right?

  • @sathiskumarp
    @sathiskumarp 2 года назад

    static variable is not possible, we need to remove either we can keep final

  • @rpstudio9298
    @rpstudio9298 2 года назад

    How to do this same using JDK 8 features???

    • @varanasivamsikrishna7795
      @varanasivamsikrishna7795 2 года назад

      1) convert the array to list
      2) Then, list.stream().collect(Collectors.groupingBy(Function.indentity(), Collectors.counting()));

  • @ashishsingh8222
    @ashishsingh8222 2 месяца назад

    Map numsInMap = Arrays.stream(nums).boxed()
    .collect(Collectors.groupingBy(x -> x, Collectors.counting()));
    numsInMap.entrySet().forEach(x -> System.out.println(x.getKey() + " -> " + x.getValue()));
    for java 8

  • @nanisai8264
    @nanisai8264 2 года назад

    Int y is an instance variable, so it can't be static.

    • @pinkubose2994
      @pinkubose2994 2 года назад

      Can you please explain sir?
      I couldn't understand, please explain.

    • @cloudtech5260
      @cloudtech5260  2 года назад +2

      Local variables cannot be static. Static variables can only belong to class level. 👍

  • @rajuveerla9352
    @rajuveerla9352 2 года назад

    Bro plz post python interview questions

  • @letsexplorewithsoumyaranja2045
    @letsexplorewithsoumyaranja2045 2 года назад

    Remove the static keyword from the y variable.