首页 > 其他分享 >J2ME数组的复制及连接操作

J2ME数组的复制及连接操作

时间:2023-09-22 12:33:00浏览次数:33  
标签:return int a1 length 复制 数组 J2ME byte a2


public class Arrays {
   /**
    * 构造函数私有,这样可以保证只能通过:类名.静态方法 或 类名.静态方法 来访问内部数据,
    * 而不可以通过创建本类的对象来进行访问
    */
   private Arrays() {
   }
 
   /**
    * 复制一个跟源byte数组一样的byte数组
    * @param rSource 源byte数组
    * @return 跟源byte[]数组一样的byte[]数组
    */
   static public byte[] copy(byte[] rSource) {
      byte[] aResult = new byte[rSource.length];
      System.arraycopy(rSource, 0, aResult, 0, aResult.length);
 
      return aResult;
   }
 
   /**
    * 复制一个跟源int数组一样的int数组
    * @param rSource 源int数组
    * @return 跟源int数组一样的int数组
    */
   static public int[] copy(int[] rSource) {
      int[] aResult = new int[rSource.length];
      System.arraycopy(rSource, 0, aResult, 0, aResult.length);
 
      return aResult;
   }
 
   /**
    * 比较两个byte数组的内容及长度是否相等.
    * @param a1 第一个byte数组
    * @param a2 第二个byte数组
    * @return 相等的话返回true,否则返回false
    */
   static public boolean equals(byte[] a1, byte[] a2) {
      if ( (a1 == null) || (a2 == null)) {
         return a1 == a2;
      }
 
      int nLength = a1.length;
 
      if (nLength != a2.length) {
         return false;
      }
 
      for (int i = 0; i < nLength; i++) {
         if (a1[i] != a2[i]) {
            return false;
         }
      }
 
      return true;
   }
 
   /**
    * 比较两个int数组的内容及长度是否相等.
    * @param a1 第一个int数组
    * @param a2 第二个int数组
    * @return 相等的话返回true,否则返回false
    */
   static public boolean equals(int[] a1, int[] a2) {
      if ( (a1 == null) || (a2 == null)) {
         return a1 == a2;
      }
 
      int nLength = a1.length;
 
      if (nLength != a2.length) {
         return false;
      }
 
      for (int i = 0; i < nLength; i++) {
         if (a1[i] != a2[i]) {
            return false;
         }
      }
 
      return true;
   }
 
   /**
    * 连接两个byte数组,之后返回一个新的连接好的byte数组
    * @param a1
    * @param a2
    * @return 一个新的连接好的byte数组
    */
   static public byte[] join(byte[] a1, byte[] a2) {
      byte[] result = new byte[a1.length + a2.length];
 
      System.arraycopy(a1, 0, result, 0, a1.length);
      System.arraycopy(a2, 0, result, a1.length, a2.length);
 
      return result;
   }
 
   /**
    * 连接两个int数组,之后返回一个新的连接好的int数组
    * @param a1
    * @param a2
    * @return 一个新的连接好的int数组
    */
   static public int[] join(int[] a1, int[] a2) {
      int[] result = new int[a1.length + a2.length];
 
      System.arraycopy(a1, 0, result, 0, a1.length);
      System.arraycopy(a2, 0, result, a1.length, a2.length);
 
      return result;
   }
}

标签:return,int,a1,length,复制,数组,J2ME,byte,a2
From: https://blog.51cto.com/u_6730273/7563719

相关文章

  • PG-DBA培训20:PostgreSQL逻辑复制技术与项目实战
    一、风哥PG-DBA培训20:PostgreSQL逻辑复制技术与项目实战本课程由风哥发布的基于PostgreSQL数据库的系列课程,本课程属于PostgreSQL主从复制与高可用集群阶段之PostgreSQL逻辑复制技术与项目实战,学完本课程可以掌握PostgreSQL逻辑复制基础与架构,PostgreSQL逻辑复制配置之内置默认,Post......
  • MySQL 主从复制与读写分离
    MySQL主从复制与读写分离1、什么是读写分离?读写分离,基本的原理是让主数据库处理事务性增、改、删操作(INSERT、UPDATE、DELETE),而从数据库处理SELECT查询操作。数据库复制被用来把事务性操作导致的变更同步到集群中的从数据库。2、为什么要读写分离呢?因为数据库的“写”(写10000......
  • Array 数组的几种方法
    1.arr.keys()返回数组的键名2.arr.values()返回数组的值3.arr.entries()返回数组的键和值4.arr.reduce() 接受两个参数:一个是对数组每个元素执行的回调方法,一个是初始值letsum=arr.reduce(function(prev,cur,index,array){returnprev+cur},0)console.l......
  • 笔试_0001(数组A内无重复,如A=[a,b,c])
      publicstaticvoidmain(String[]args){//question1();//question2();System.out.println(~1+1);}privatestaticvoidquestion1(){/*思路,规律:利用字符串的包含和替换。*/......
  • 默认选中数组最多的tab
    初次默认选中数组最多的tabinitTab:true,tabs:[],activeTab:0,if(this.initTab){letmaxUnread=-1;letactiveTabIndex=-1;for(leti=0;i<this.tabs.length;i++){if(this.tabs[i].unread>maxUnread){ maxUnread=this.tabs[i].unread; ......
  • postgresql主从复制状态检查
    确定主从库方法一ps-ef|grep"wal"|grep-v"grep如果输出walsender…streaming进程说明当前数据库为主库如果输出walreceiverstreaing进程说明当前数据库为备用库方法二select*frompg_stat_replication;在主库上查询pg_stat_replication视图,如果返回记录说明是主库,备库上......
  • 数组反转以及二位数组
    数组反转就是新生成一个数组,来反向接受原数组位置的数据publicstaticint[]reverse(int[]array){int[]reverse=newint[]array.length;for(inti=0,j=array.lenhth;i<array.length;i++,j--){ reverse[j]=array[i];}returnreverse;}假如遍历数组并输出的函数pri......
  • Leetcode刷题448.找到所有数组中消失的数字
    给你一个含 n 个整数的数组 nums ,其中 nums[i] 在区间 [1,n] 内。请你找出所有在 [1,n] 范围内但没有出现在 nums 中的数字,并以数组的形式返回结果。 示例1:输入:nums=[4,3,2,7,8,2,3,1]输出:[5,6]示例2:输入:nums=[1,1]输出:[2] 提示:n==nums.lengt......
  • 数组
    感觉不太好记定义有两种int[]a={1,2,3,4,5,6,7}//这种是静态初始化int[]a=newint[10]//这种是动态初始化动态初始化感觉赋值有点费劲a[0]=1;//或者用for循环来赋值还有实现一个简单的四则运算计算器,主要用了switch语句和scanner代码如下;就是很简单的那种四则运算的......
  • 数组初学习
    数组创建数组是相同类型的有序组合//创建命令int[]nums=newint[个数]下图为实践计算数组中所有数的和三种初始化和内存分析数组被声明时会存在栈中,真正创建时数组才会存在堆中,我们无法调用超过数组最大下标的数组,会报错java.lang.ArrayIndexOutOfBoundsException意思是......