【使用Java实现寻找一个字符串中最长的对称字符串】教程文章相关的互联网学习教程文章

java-使用字符串和数组中的int排序【代码】

我的作业要求我制作一个电视节目,我可以在其中输入节目,删除,修改和排序节目.我坚持的是排序部分.该程序会提示用户输入节目名称,新剧集首播的日期和时间,这些都存储在数组中.它按键名称,日期和时间(字母和数字)排序. 该程序提示用户输入这些键之一,然后该程序需要按该键对显示进行排序(按天排序将按字母顺序排序). 我制作了一个类,并使用数组保存了输入的节目.这是课程:public class showInfo { String name; String day;...

Java字符串池相关的疑问

我试图了解字符串池是如何工作的.我已经浏览了许多站点,最后我现在更加困惑了.让我在这里放下我的怀疑.有人帮助我了解它们. 1)字符串池在哪里存在?在堆还是在方法区域? 2)字符串s =“ Hello world”; -这足以创建一个字符串.由于字符串是不可变的,一旦创建了字符串就无法更改,那么使用String s = new String(“ Hello World”)吗? 虽然它会强制JVM在堆中而不是在字符串池中创建一个新的String对象,但是对新的Strin...

Java字符串正则表达式替换方法从替换中删除反斜杠【代码】

我只花了1个小时来追踪我认为不正常的行为在String类中使用replaceAll / replaceFirst. 如果替换字符串中有反斜杠,则在替换时将其删除更换.然后,我读到可以使用Matcher.quoteReplacement(String)来创建一个适当的替换字符串,但是我的问题是为什么?我可以期待如果不这样做,则第一个参数应使用Patter.quote(String)进行转义想要特殊的意思,但我看不出更改替换的理由:( 是的,我将开始使用replace(CharSequence,CharSequence),只想知道...

java-将字符串更改为Char数组【代码】

将值存储为字符串后,如何遍历字符串并将每个值分配给char数组?还必须计算数组中每个元音的出现次数. 这是我当前的代码:public class Part1_5 {/*** Method that gets user name and stores it as a string. Each value then* assign to a char array. no of vowels are counted and no of each printed*/public static void main(String[] args) {// Setting up scannerScanner scanner = new Scanner(System.in);// declaring s...

java-根据字符串的第一个字符从ArrayList中删除重复的条目【代码】

我想从数组列表中删除一个字符串,该字符串的第一个字符与另一个字符串相同. 例List<String> collection = new ArrayList<String>();collection.add("1 w a"); collection.add("2 r a"); collection.add("1 r b"); collection.add("2 r b"); collection.add("3 w a");输出量collection = ["1 w a", "2 r a", "3 w a"]我尝试使用哈希集和链接哈希集.解决方法:使用最少的第一个字符存储空间,您可以查找并删除重复项:List<Character> ...

java-创建一个二维字符串数组anArray [2] [2]【代码】

我目前正在学习Java自学课程,但完全被我的一项任务困扰,有人可以给我一些建议吗?请记住,我是Java的新手,所以我需要它像它一样简单. 问题:3.创建一个名为TwoDimArray的Java程序并实现以下内容:Create a two dimensional string array anArray[2][2]. Assign values to the 2d array containing any Country and associated colour. Example:France Blue Ireland Green Output the values of the 2d array using nested for loops...

java-使用JDBC时使用字符串还是char []作为密码?【代码】

从安全角度来看.最佳实践是不要使用String存储密码,而要使用char [].这是否适用于随时使用密码?例如,使用JDBC时可以使用字符串来保存密码吗?public final void Login(String username, String password){ ... conn = DriverManager.getConnection(url, username, password); ... }还是可以在这里使用char []代替String?解决方法:我不知道我是否接受您的假设,即在系统资源(例如JDBC数据库连接)的上下文中,char []比String更安全....

从java中的字符串读取json【代码】

如果JSON数据在字符串中,如何从下面的JSON读取数据{"name": "test","values": [{"valu": "23","valu1": "24","valu2": "25"}] }解决方法:使用Gson和Gson#fromJson方法之一 fromJson(String, Class)YourType o = new Gson().fromJson("your json string", YourType.class);fromJson(Reader, Class)YourType o = new Gson().fromJson(new StringReader("your json string"), YourType.class);简单的例子: 定义您想要将json数据映射到...

java-如何检测字符串中的空格?【代码】

String test="This is a simple text"是否有可能检测空格并通过查看该空格来写下一行?我的意思是拥有这样的控制台输出:This is a simple text++++ ++ + ++++++ ++++解决方法: public class StringPlus {public static void main(String[] args) {String test="This is a simple text";for(char c: test.toCharArray()){System.out.print((c == ' ') ? " ":"+");}} }

java-Android中的字符串加密【代码】

我正在使用代码进行加密和加密.它没有给出字符串结果.字节数组未转换为字符串.我几乎尝试了所有将字节数组转换为char的方法,但未给出结果.public class EncryptionTest extends Activity {EditText input, output, outputDecrypt; String plain_text; byte[] key, encrypted_bytes,keyStart,byte_char_text,decrpyted_bytes ;@Override protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);s...

java-为什么串联两个字符串并将其作为参数传递不会创建新的字符串对象?【代码】

我正在学习并准备获得Java SE 6认证.我使用的是Kathy Sierra和Bert Bates的书“ Sun Java 6认证程序员学习指南”.我实际上是在Strings,I / O和Parsing. 他们提供了一个我可能希望在考试中看到的那种恶魔般的String问题的示例:String s1 = "spring "; String s2 = s1 + "summer "; s1.concat("fall "); s2.concat(s1); s1 += "winter "; System.out.println(s1 + " " + s2);What is the output? For extra credit, how many String...

java-如何测试字符串数组搜索的速度?【代码】

我为Java类编写了一个程序,该程序用于在String数组中搜索特定目标.程序从数组的开头到数组的结尾搜索目标,然后从数组的结尾到数组的开头搜索目标.我应该测试两种搜索的速度,看看哪个更快.我该如何测试? 这是程序:public class LinearStringSearch {// Array filled with random StringsString[] randomStrings = {"apple", "yellow", "fire", "wood", "zinc", "ram", "mouse", "fish", "cheese", "dirt"};// Save target argumen...

错误java.lang.NumberFormatException:对于输入字符串:“”【代码】

我正在尝试读取此文件C101VEHICLE NUMBER CAPACITY25 200CUSTOMER CUST NO. XCOORD. YCOORD. DEMAND READY TIME DUE DATE SERVICE TIME0 40 50 0 0 1236 0 1 45 68 10 912 967 90 2 45 70 30 825 870 90 3 42 66 10 65 ...

Java-Android:如何从字符串创建位图?【代码】

我在字符串中有一些文本想要保存为图像.现在我有以下代码:private void saveImage(View view){String mPath = Environment.getExternalStorageDirectory().toString() + "/" + "spacitron.png"; String spacitron = "spacitron";Bitmap bitmap = BitmapFactory.decodeByteArray(spacitron.getBytes(), 0, spacitron.getBytes().length*5);OutputStream fout = null;File imageFile = new File(mPath);try {fout = new FileOutput...

java-如果我们使用新的String(“ abcd”),是否在堆中创建了字符串对象?【代码】

这个问题已经在这里有了答案: > How do I compare strings in Java? 23个String s1 = new String("anil");String s2 = s1.toUpperCase();String s3 = s1.toLowerCase();System.out.println(s1 == s2);System.out.println(s1 == s3);如果在堆中创建的字符串对象都为false.但是它给出的是false,true.解决方法: String s1 = new String("anil");该语句创建一个新对象 和这...