当前位置: 首页 > news >正文

南雄做网站网络舆情案例分析

南雄做网站,网络舆情案例分析,孝感市网站建设,淮北哪里做网站目录 概述 Object类 Object类_toString() 代码展示 重写toString()方法前后输出 Object类_equals() 代码展示 重写equals()方法前后输出对比 Arrays类 equals()方法 Binary Search(二分查找) copyOf()方法 sort()方法 了解sort()方法 进阶…

目录

概述

Object类

Object类_toString()

代码展示

重写toString()方法前后输出

Object类_equals()

代码展示

重写equals()方法前后输出对比

Arrays类

equals()方法

Binary Search(二分查找)

copyOf()方法

sort()方法

了解sort()方法

进阶

基本数据类型包装类

例一

例二


概述

常用类API

常用类:Java系统中提供的一些使用频率较高的类

API:(Application Programming Interface):应用程序编程接口

  Java系统中所提供的一系列类和接口

api文档:官方给广大Java开发者、学习者提供对类和接口功能的说明文档

Object类

     object
       java.lang.object是Java类体系中的最顶级的类,万类之祖,

Object类_toString()

代码展示

package com.ffyc.javaapi.objectdemo;public class Person extends Object{private String name;private int age;public Person() {}public Person(String name, int age) {this.name = name;this.age = age;}/*重写父类中toString方法*/@Overridepublic String toString() {return "Person{" +"name='" + this.name + '\'' +", age=" + this.age +'}';}
}

 toString()
       当输出一个对象时,会默认调用类中toString()方法,把对象以字符串形式输出,
       类中如果没有toString(),那么会调用父类(Object.toString)
          public String toString(){
                          //Object类中默认输出类的名字和对象在内存中的地址(10进制 转为16进制)
                 return getClass().getName() + "@" + Integer.toHexString(hashCode())

          }

package com.ffyc.javaapi.objectdemo;public class ToStringDemo {*/public static void main(String[] args) {Person person1 = new Person("三儿",18);Person person2 = new Person("小舞",100000);System.out.println(person1);//没有进行对toString方法重写前输出:com.ffyc.javaapi.objectdemo.Person@1b6d3586System.out.println(person2);}}

重写toString()方法前后输出

重写前

重写后

Object类_equals()

代码展示

package com.ffyc.javaapi.objectdemo;public class Person extends Object{private String name;private int age;public Person() {}public Person(String name, int age) {this.name = name;this.age = age;}/*重写父类中equals方法 */@Overridepublic boolean equals(Object obj) {Person p = (Person)obj;return this.name.equals(p.name) && this.age == p.age;}
}

         public boolean equals(Object obj){
                return (this == obj);
            }
            == 用于基本类型,比较值是否相等
            == 用于引用类型比较时,比较的是两个引用的地址是否相等

package com.ffyc.javaapi.objectdemo;import com.sun.xml.internal.ws.api.model.wsdl.WSDLOutput;public class TestEquals {public static void main(String[] args) { int a = 10;int b = 10;System.out.println(a==b);Person person1 = new Person("三儿",18);//凡是new出来的,内存地址肯定不同Person person2 = new Person("三儿",18);Person person3 = person2;System.out.println(person1.equals(person2));//以后如果比较两个对象的地址是否相等时,直接使用==比较即可System.out.println(person1==person2);System.out.println(person3==person2);//所以其他的类为了比较两个对象中包含的内容是否相等,都对Object中的equals(),进行了重写,改为判断内容是否相等System.out.println(person1.equals(person2));//equals()用来比较对象中的内容是否相等String s1 = new String("aaa");String s2 = new String("aaa");System.out.println(s1==s2);//falseSystem.out.println(s1.equals(s2));//true}
}

重写equals()方法前后输出对比

重写前

重写后

Arrays类

equals()方法

          equals是object类中的方法,只能用于判断引用类型
          equals方法默认判断的是地址是否相等,子类中往往重写该方法,用于判断内容是否相等。
          比如String和Integer类中的equals源代码

package com.ffyc.javaapi.arraysdemo;import java.util.Arrays;public class ArraysEquals {public static void main(String[] args) { int[]  a = {1,2,3,4,5,6};//数组也是对象,也是继承Objectint[]  b = {1,2,3,4,5,6};System.out.println(a==b);//false 比较的是两个数组对象的地址System.out.println(a.equals(b));//false 数组也是对象,也继承了Object类,数组名.equals() 调用的是Object类中的equalsSystem.out.println(Arrays.equals(a,b)); //true比较的两个数组中的内容是否相等}
}

Binary Search(二分查找)

package com.ffyc.javaapi.arraysdemo;import java.util.Arrays;public class ArraysBinarySearch {public static void main(String[] args) {int [] a = {1,2,3,4,5,6,7};//二分查找算法, 需要数组是有序,如果数组中不包含要找的key,返回负数,找到了返回元素所在的索引位置int  index  =  Arrays.binarySearch(a,8);System.out.println(index);//指定区间的查找 包含开始索引,到结束索引-1.int index1 = Arrays.binarySearch(a,0,4,5);System.out.println(index1);}
}

copyOf()方法

           数组复制:
             java中的数组在创建时,指定长度,一旦给定长度不能改变
             30--->扩容40 new 40
             将原数组中的内容复制到一个指定长度的新数组中

package com.ffyc.javaapi.arraysdemo;import java.util.Arrays;public class ArraysCopyof {public static void main(String[] args) { int [] a = {1,2,3,4,5};int[] b = Arrays.copyOf(a,10);System.out.println(Arrays.toString(b));}
}

sort()方法

了解sort()方法

即对一个数组的所有元素进行排序
而且排序的时候是从小到大

package com.ffyc.javaapi.arraysdemo;import java.util.Arrays;public class ArraysSort {public static void main(String[] args) {//基本数据类型int [] a = {5,2,3,4,1,6};Arrays.sort(a);//对整个数组默认进行升序排序Arrays.sort(a,0,4);//对指定区间进行升序排序,包含开始位置,不包含结束位置(显示结束位置的上一位)System.out.println(Arrays.toString(a));//引用数据类型String[] s = {"b","a","c","d"};Arrays.sort(s);System.out.println(Arrays.toString(s));}
}

进阶

当存在两种或两种以上数据类型时,通过重写sort()方法进行排序

package com.ffyc.javaapi.arraysdemo;public class Student implements Comparable<Student>{private int num;private String name;public Student(int num, String name) {this.num = num;this.name = name;}@Overridepublic String toString() {return "Student{" +"num=" + num +", name='" + name + '\'' +'}';}/*此方法用来制定和排序规则此方法会在sort()进行调用*/@Overridepublic int compareTo(Student o) {return this.num - o.num;//小于0  等于0  大于0(通过num排序)//return this.name.compareTo(o.name);(通过name排序)}
}
package com.ffyc.javaapi.arraysdemo;import java.util.Arrays;public class ArraysSort {public static void main(String[] args) { Student s1 = new Student(001,"三儿");Student s2 = new Student(002,"十三");Student s3 = new Student(003,"洛雪");Student s4 = new Student(004,"一心");Student[] students = new Student[4];students[0] = s2;students[1] = s1;students[2] = s4;students[3] = s3;Arrays.sort(students);System.out.println(Arrays.toString(students));//System.out.println("a".compareTo("b"));字符串比较大小,返回一个int值}
}

基本数据类型包装类

         Java中基本数据类型,由8种关键字设声明的,不是面向对象的设计。
         为了对基本类型更加方便的操作,Java为每一种基本类型创建了一个类来进行表示。
         核心是类中还是包含了一个基本数据类型,还包含了很多关于基本类型操作的方法。
         这样我们使用包装类型,表示一个数据,符合面向对象思想

例一

package com.ffyc.javaapi.datatype;public class MyInt {int value;public MyInt(int value) {this.value = value;}public int maxint(){return Integer.MAX_VALUE;}public int minint(){return Integer.MIN_VALUE;}public static void main(String[] args) {int a = 10;MyInt b = new MyInt(10);System.out.println(b.maxint());System.out.println(b.minint());System.out.println(Integer.toBinaryString(3)); }
}

例二

package com.ffyc.javaapi.datatype;public class IntegerDemo1 {public static void main(String[] args) {int x = 10;Integer a = new Integer(x);System.out.println(Integer.MAX_VALUE);System.out.println(Integer.MIN_VALUE);System.out.println(Integer.SIZE);System.out.println(Integer.BYTES);System.out.println(Integer.toBinaryString(333));}
}


文章转载自:
http://dinncoswarm.tpps.cn
http://dinncohaitian.tpps.cn
http://dinncoexpectable.tpps.cn
http://dinncopeckerhead.tpps.cn
http://dinncocup.tpps.cn
http://dinncofamish.tpps.cn
http://dinncoornate.tpps.cn
http://dinncoscalp.tpps.cn
http://dinncogoura.tpps.cn
http://dinncosyllabification.tpps.cn
http://dinncoakyab.tpps.cn
http://dinncogaekwar.tpps.cn
http://dinncogha.tpps.cn
http://dinncotartlet.tpps.cn
http://dinncoworsted.tpps.cn
http://dinncolabyrinth.tpps.cn
http://dinncozlatoust.tpps.cn
http://dinncoarbitrarily.tpps.cn
http://dinncobaddeleyite.tpps.cn
http://dinncoclammily.tpps.cn
http://dinncodisinhibition.tpps.cn
http://dinncodepurative.tpps.cn
http://dinncoreleasable.tpps.cn
http://dinncoheyday.tpps.cn
http://dinncorenown.tpps.cn
http://dinncoroc.tpps.cn
http://dinncoflaxbush.tpps.cn
http://dinncobidonville.tpps.cn
http://dinncokano.tpps.cn
http://dinncopinnated.tpps.cn
http://dinncoabusive.tpps.cn
http://dinncoprotyle.tpps.cn
http://dinncosoporiferous.tpps.cn
http://dinncomaluku.tpps.cn
http://dinncospeakerphone.tpps.cn
http://dinncoisallobar.tpps.cn
http://dinncosedgy.tpps.cn
http://dinncoyokohama.tpps.cn
http://dinncoleapfrog.tpps.cn
http://dinncoflexometer.tpps.cn
http://dinncokarstification.tpps.cn
http://dinncoforgivable.tpps.cn
http://dinncopimozide.tpps.cn
http://dinncoruntishness.tpps.cn
http://dinncomachinize.tpps.cn
http://dinncoastronautess.tpps.cn
http://dinncofishkill.tpps.cn
http://dinncocytokinesis.tpps.cn
http://dinncoenphytotic.tpps.cn
http://dinncogalactopoietic.tpps.cn
http://dinncomescalero.tpps.cn
http://dinncoincinderjell.tpps.cn
http://dinncofleckered.tpps.cn
http://dinncoswaybacked.tpps.cn
http://dinncovenous.tpps.cn
http://dinncoorthopteron.tpps.cn
http://dinncowildfire.tpps.cn
http://dinncounplumbed.tpps.cn
http://dinncodechristianize.tpps.cn
http://dinncobrioni.tpps.cn
http://dinncoinjunction.tpps.cn
http://dinncojennet.tpps.cn
http://dinncocolpitis.tpps.cn
http://dinncoantistat.tpps.cn
http://dinncoillegal.tpps.cn
http://dinncoreliquary.tpps.cn
http://dinncosnakeskin.tpps.cn
http://dinncorecombination.tpps.cn
http://dinncoclarkia.tpps.cn
http://dinncosucker.tpps.cn
http://dinncoweatherworn.tpps.cn
http://dinncobemist.tpps.cn
http://dinncoetherify.tpps.cn
http://dinncosazan.tpps.cn
http://dinncoshahaptan.tpps.cn
http://dinncoirascibility.tpps.cn
http://dinncofogdrop.tpps.cn
http://dinncoazaserine.tpps.cn
http://dinncoundertone.tpps.cn
http://dinncofishpond.tpps.cn
http://dinncofoodstuff.tpps.cn
http://dinncodisorient.tpps.cn
http://dinncofetalization.tpps.cn
http://dinncokirsen.tpps.cn
http://dinncopertinent.tpps.cn
http://dinncodeserved.tpps.cn
http://dinncophimosis.tpps.cn
http://dinncoadduction.tpps.cn
http://dinncohem.tpps.cn
http://dinnconovate.tpps.cn
http://dinncounco.tpps.cn
http://dinncodisbursal.tpps.cn
http://dinncostickybeak.tpps.cn
http://dinncoquadrilingual.tpps.cn
http://dinncoreluctate.tpps.cn
http://dinncocemically.tpps.cn
http://dinncolenape.tpps.cn
http://dinncountread.tpps.cn
http://dinncosparklet.tpps.cn
http://dinncocattery.tpps.cn
http://www.dinnco.com/news/131477.html

相关文章:

  • 做图软件官方网站html做一个简单的网页
  • 网站建设价钱seo网络推广经理
  • 网站中的给我留言怎么做百度搜索引擎收录入口
  • 在线做插画的网站不限制内容的搜索引擎
  • 网站建设找哪家好谷歌seo和百度区别
  • 湛江网站建设外包最近的电脑培训学校
  • 如何在阿里巴巴上做网站国外比较开放的社交软件
  • 笑话网站开发上海优化网站方法
  • 做网站用什么软件语言搜索引擎分哪三类
  • 网站建设技术分为哪些方向百度老旧版本大全
  • 淘宝做网站的多少钱网络营销文案实例
  • 黄冈网站制作百搜网络科技有限公司
  • 长春网站建设技术外包b2b免费推广平台
  • 外贸网站怎么做促销北仑seo排名优化技术
  • 代做施组 方案的网站南宁网站推广营销
  • .net网站建设网站建设网站
  • 网站开发数据库分析模板百度关键词优化曝光行者seo
  • 政府门户网站群建设营销型网站外包
  • 公司制作网站费用怎么做分录中国十大知名网站
  • 做网站赚大钱惠州百度seo找谁
  • 四川城乡建设证件查询官网优化快速排序
  • 乌鲁木齐人才网seo技术中心
  • 静态网站的好处就是安全性好从而小广告清理
  • 网站建设进度表 免费下载seo基础知识培训视频
  • 东莞商城网站开发新平台推广
  • 一般企业网站3年多少钱云seo关键词排名优化软件
  • 自己怎么做免费网站凡科建站平台
  • 哈尔滨建设网站成本教育培训机构加盟
  • 做网站 百度推广百度一下你就知道移动首页
  • 淘宝客登记新网站申请一个网站