Java compareTo一步一步执行(Java compareTo step by step execution)
我基本了解Java
compareTo
方法按lexicographically compares
两个字符串。 我在这里阅读了基础知识Java中的字符串比较我有以下示例:
public class CompareTo { public static void main(String args[]) { String str1 = "String"; String str2 = "compareTo"; String str3 = "String"; int var1 = str1.compareTo( str2 ); System.out.println("str1 & str2 comparison: "+var1); int var2 = str1.compareTo( str3 ); System.out.println("str1 & str3 comparison: "+var2); } }
我得到
var1 = -16
和var2 = 0
。如果有人一步一步地向我解释这个
Lexicographic comparison
,那将会有很大的帮助。谢谢。
I have basic understanding that Java
compareTo
methodlexicographically compares
two strings. I have read basics here String Comparison in JavaI have following example:
public class CompareTo { public static void main(String args[]) { String str1 = "String"; String str2 = "compareTo"; String str3 = "String"; int var1 = str1.compareTo( str2 ); System.out.println("str1 & str2 comparison: "+var1); int var2 = str1.compareTo( str3 ); System.out.println("str1 & str3 comparison: "+var2); } }
I get
var1 = -16
andvar2 = 0
.If someone explains me this
Lexicographic comparison
step by step It would be of great help.Thanks.
更新时间:2022-09-09 13:09
最满意答案
相关问答
更多-
与开发团队核实,他们将其标记为界面中的错误。 在这里检查信息 Checked with the dev team, and they marked it as a bug in the interface. Check info here
-
getInstrumentation().getContext() 这将返回表示androidTest源集的Context 。 如果您的资源在其他地方(例如, main ),请使用: getInstrumentation().getTargetContext() getInstrumentation().getContext() This returns a Context representing your androidTest source set. If your resources are ...
-
所以我会发布我认为是我的问题的解决方案。 在我上面的代码中添加一行后,给ViewPager一个“随机”ID; 它设法解决了我的问题。 起初我相信设置自己的身份证是不好的做法,但显然有合法的方法来做到这一点。 也就是通过创建一个ids.xml文件,并让Android生态系统为您生成ID。 我建议您查看这些SO帖子以获取更多信息 - 这里和这里 。 否则,我会建议您为您的布局创建一个XML文件,并在您的Activity获取ViewPager (而不是以编程方式实例化),但最终取决于您要完成的任务。 So I'l ...
-
更改 dateTime.setText(app.getTotalDl()); 至 dateTime.setText(String.valueOf(app.getTotalDl())); 有不同版本的setText - 一个需要一个String,一个使用一个int资源id。 如果你传递一个整数,它将尝试查找相应的字符串资源ID - 它找不到,这是你的错误。 我猜app.getTotalDl()返回一个int。 您需要特别指出setText将其设置为此int的String值。 setText(int res ...
-
我们在Java代码中引用的R值(例如R.layout.input_8 )是代码生成的R类上的public static final int值。 您将在模块的build/generated/source/r/目录中找到该类。 该文件相当大,但你会看到像这样的东西: public static final class layout { public static final int activity_main=0x7f050000; } 该编号( 0x7f050000 )由构建工具( aapt ...
-
我发现问题是由于用于活动的资源已经破坏。 As I found the problem was due to the fact that the resources used for the activity have destroyed.
-
您正在给textview一个整数值,以便它可以在R.java中找到匹配的ID 尝试像这样解析这个值 @Override public void onLocationChanged(Location arg0) { if(arg0!=null) { tv1.setText(String.valueOf(arg0.getLongitude())); //there is an error tv2.setText(String.valueOf(arg0.getLat ...
-
看这里: adapter = new ViewPagerAdapter(getSupportFragmentManager(), Titles, Numboftabs, mContext); 从这里开始, mContext将mContext null 。 因为你没有在onCreate方法中为mContext变量赋予任何参考。 将其更改为: adapter = new ViewPagerAdapter(getSupportFragmentManager(), Titles, Numboftabs, Main ...
-
Android.Content.Res.Resources只有getObject
(Android.Content.Res.Resources has only getObject [2023-12-16]) 根据文档 ,有一个String GetString (Int32 id)函数。 您需要使用getResources()从应用程序上下文中获取Resources实例,然后您可以调用该方法。 According to the docs, there is a String GetString (Int32 id) function. You need to get a Resources instance from the application context, using getResources(), t ... -
在res目录下创建一个目录drawable-v21在drawable-v21下添加带有ripple的drawable-v21对于21以下的Api版本,创建一个相同名称的drawable并将其添加到drawable目录下,如下所示
相关文章
更多- Solr/Lucene分布式搜索,Solr Integrate katta step3
- Solr/Lucene分布式搜索,Solr Integrate katta step1
- Solr/Lucene分布式搜索,Solr Integrate katta step2
- 数据库设计 Step by Step (1)
- 数据库设计 Step by Step (1)——扬帆启航
- 数据库设计 Step by Step (1)——扬帆启航
- 一步一步掌握java的线程机制(一)----创建线程
- 一步一步教你将普通的wifi路由器变为智能广告路由器
- 一步一步掌握java的线程机制(二)----Thread的生命周期
- 一步一步学solr:什么是solr?
最新问答
更多- 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
- 如何通过引用返回对象?(How is returning an object by reference possible?)
- 矩阵如何存储在内存中?(How are matrices stored in memory?)
- 每个请求的Java新会话?(Java New Session For Each Request?)
- css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
- 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
- xcode语法颜色编码解释?(xcode syntax color coding explained?)
- 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
- 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
- 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
- 西安哪有PLC可控制编程的培训
- 在Entity Framework中选择基类(Select base class in Entity Framework)
- 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
- 电脑二级VF有什么用
- Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
- 金华英语角.
- 手机软件如何制作
- 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
- 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
- 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
- Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
- 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
- python的访问器方法有哪些
- DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
- 在Ruby中对组合进行排序(Sorting a combination in Ruby)
- 网站开发的流程?
- 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
- 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
- 透明度错误IE11(Transparency bug IE11)
- linux的基本操作命令。。。