Java中的数组(1D)

In this tutorial I will talk about one dimensional array in
java. In the next tutorial we will learn about multidimensional array.

Array in Java

  • Array is the collection of similar type of data having contiguous

    memory location. 

  • Due to contiguous memory location the performance becomes

    fast. 

  • The biggest disadvantage of array is, we can’t increase or

    decrease its size after defining it. 

  • Array is represented by an object.
  • Array is the reference variable of proxy class. The proxy

    class is a class created by JVM at run time. We can get the name of the proxy

    class of an array by using getClass().getName() method. 

  • Array reduces the program size. For example if we want to

    store roll number of 100 students then we have to create 100 variables. It will

    make the program very large and difficult to handle. This problem can be

    solved easily by using an array of size 100. 

    Declare an Array in java

    Array can be declared in following two ways.

    Syntax
    data_type []array_name;
    data_type array_name[];
    Example
    In above example we simply declared a reference variable
    that will store the reference of an array object.

    Create an Array in java

    Array is created or instantiated using new keyword in
    following way.

    Syntax
    array_name=new data_type[size];
    Example

    The above code will create an array that can store 10
    values.

    Declare, Create and Initialize an Array in Java

    Array can be declared, created and initialized at the same
    time in the following way. In this case we don’t need to use new keyword and
    specify the size.
    int a[]={1,2,3,4,5};
    Above code will create and array of size 5 and also initialize
    it.
    Array elements can be accessed using index. The indexing
    starts from 0 and ends at n-1. Here n is the size of the array. The index comes
    inside the square brackets []. For example if you want to access third element
    of array a which we have created above then it can be done by writing a[2]. I
    have used index 2 because the first element will be at index 0, second will be
    at index 1 and third element will be at index 2. In this way we can access
    other elements also.

    Program for Array in Java

    Let’s make a simple program that will create an array, store
    some values in it and then print these values. Array elements can be accessed
    one by one using loop. In below program I have used for loop, we can also use other loops. I have manually assigned
    the values in an array; we can also take values from user.
     Program for Array in Java

    Explanation
    In above example we have created an array of size 5 and then
    initialized it. After that we are printing the values. You can see I have used
    i<5, this makes the loop to run 5 times as we have 5 elements in array.
    Instead of i<5, we can also use i<a.length. Actually length is a data
    member of Array class which gives the size of an array.

    This was all about one dimensional array in java. If you are
    facing difficulty to understand anything then ask your queries by commenting
    below.

    翻译自: https://www.thecrazyprogrammer.com/2015/05/array-in-java-1-d.html

    • 0
      点赞
    • 0
      收藏
      觉得还不错? 一键收藏
    • 0
      评论
    根据提供的引用内容,我无法直接回答您关于Java DoubleFFT_1D的音频滤波算法的问题。引用是一个Java类的路径,引用是一个关于音频帧的字节数组的声明。这些引用提供了一些关于Java和音频处理的信息,但没有提供关于具体的音频滤波算法的细节。 如果您对Java的音频滤波算法感兴趣,我可以为您提供一些常见的音频滤波算法的介绍和示例代码。以下是两种常见的音频滤波算法: 1. IIR滤波器(Infinite Impulse Response Filter,无限脉冲响应滤波器):IIR滤波器是一种数字滤波器,它使用先前的输出样本和输入样本的线性组合来计算当前的输出样本。这种滤波器可以实现各种滤波效果,如低通滤波、高通滤波和带通滤波。以下是一个简单的IIR低通滤波器的示例代码: ```java public class IIRFilter { private double[] coefficients; // IIR滤波器的系数 public double[] filter(double[] input) { double[] output = new double[input.length]; for (int i = 0; i < input.length; i++) { output[i] = coefficients[0] * input[i]; // 当前输入样本的系数乘积 for (int j = 1; j < coefficients.length; j++) { output[i] += coefficients[j] * output[i - j]; // 先前输出样本的系数乘积 } } return output; } } ``` 2. FIR滤波器(Finite Impulse Response Filter,有限脉冲响应滤波器):FIR滤波器是一种数字滤波器,它使用有限数量的输入样本和滤波器的系数来计算输出样本。这种滤波器通常用于实现特定的频率响应。以下是一个简单的FIR低通滤波器的示例代码: ```java public class FIRFilter { private double[] coefficients; // FIR滤波器的系数 public double[] filter(double[] input) { double[] output = new double[input.length]; for (int i = 0; i < input.length; i++) { output[i] = 0; for (int j = 0; j < coefficients.length; j++) { if (i - j >= 0) { output[i] += coefficients[j] * input[i - j]; // 输入样本和系数的乘积 } } } return output; } } ``` 这些示例代码演示了如何在Java实现IIR和FIR滤波器。您可以根据您的需求和具体的音频滤波算法来调整这些代码。
    评论
    添加红包

    请填写红包祝福语或标题

    红包个数最小为10个

    红包金额最低5元

    当前余额3.43前往充值 >
    需支付:10.00
    成就一亿技术人!
    领取后你会自动成为博主和红包主的粉丝 规则
    hope_wisdom
    发出的红包
    实付
    使用余额支付
    点击重新获取
    扫码支付
    钱包余额 0

    抵扣说明:

    1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
    2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

    余额充值