首页 \ 问答 \ U盘启动进去CDlinux桌面后运行 /etc/init.d/networking restart

U盘启动进去CDlinux桌面后运行 /etc/init.d/networking restart

U盘启动进去CDlinux桌面后运行 /etc/init.d/networking restart为什么没有networking这个文件???
更新时间:2022-10-19 12:10

最满意答案

可以使用正则表达式进行提取字符串里面的数字:
public class MyTest {
    public static void main(String[] args) throws Exception {
        List

  prods = new 
 ArrayList
 
  ();
        prods.add("5斤");
        prods.add("15袋");

        String p = null;
        for (int i = 0; i < prods.size(); i++) {
            p = prods.get(i);
            String str = p.replaceAll("([0-9]+)(.*)$", "$1");
            System.out.println(str); 
        }
    }
}
希望可以帮到你
 

其他回答

我的集合里

是什么意思?字符串的意思?
如果是字符串的话。
可以用replaceAll加正则替换。
str.replaceAll("\D","");
String str="5jjin15daidafa";
System.out.println(str.replaceAll("\\D",""));
你说集合,应该是遍历,然后用正则替换就好了。
你的意思就是说,要写一个程序,来想办法把你的集合里面的所有数字提取出来是吗??我这里以数组为例写了一个demo,测试过了的

import java.util.regex.Pattern;
public class GetNumbersTest {
 public static void main(String[] args) {
  String[] words=new String[]{"5斤","15袋","30包"};
  String[] result=getNumbers(words);
  for(String s:result){
   System.out.println(s);
  }
 }
 public static String[] getNumbers(String[] words){
  String[] result=new String[words.length];;
  for(int j=0;j

    



                

 


 
    
按照你说的写了个小列子

package com.zwd.first;

import java.util.ArrayList;
import java.util.List;

public  class Test2  {
	public static void main(String[] args) {

   List

  list=new ArrayList
 
  ();
   list.add("5斤");
   list.add("15袋");
   for(String s:list){
	   System.out.println(s.substring(0, s.length()-1));
   }
	}

}
 
一、“==”比较的是内存地址是否相等:
1) string b = "8)",这个"8)"是最简单的字符串常量(直接写出来的,没有通过计算或其它逻辑处理得到),它存放于内存中的静态区,")"同样也是最简单的字符串常量;
2) string c = b.substring(b.length()-1,c的结果虽然也是")",但它是对字符串常量b调用substring方法得到的,一调用这个方法,新的对象就产生了,新对象位于堆内存中。
3) c和直接拼写出来的")"是不同的2个对象,2个对象的内存地址必须不一样,所以c==")"是false。

二、“equals”是实际用的最多的(而“==”只是出现在练习题中),它只要2个字符串对象长的一样就为true,c.equals(")")一定是true。实际开发当中,我们需要比较的字符串,确实只是想知道它们长得一不一样,至于是不是同一个内存--从来不会遇到这种问题。

总之,string是有点特殊的类型,多看几个练习就了解规则了(规则都是人定的,没有太多理由)。
ArrayList

  list=new ArrayList
 
  ();   
     list.add("我5斤");   
     list.add("你的15袋");   
     for(String s:list){    
      for (int i=0;i
  
    



                

   


   
    
  
 

相关问答

更多
  • java中的subString[2022-07-04]

    substring(参数)是java中截取字符串的一个方法 有两种传参方式 一种是public String substring(int beginIndex) 返回一个新的字符串,它是此字符串的一个子字符串。该子字符串从指定索引处的字符开始,直到此字符串末尾。 另一种是public String substring(int beginIndex, int endIndex) 返回一个新字符串,它是此字符串的一个子字符串。该子字符串从指定的 beginIndex 处开始,直到索引 endIndex - 1 ...
  • spm.substring(0,5)=="table" 这条语句判断的是spm.substring(0,5)返回的字符串和“table”是否是在同一个存储空间,显然他们不是同一个对象 spm.substring(0,5).equals("table") 而equals方法判断的()内的内容是否和spm.substring(0,5)得到的string中存储的内容相同,所以应该用equals()方法
  • 可以使用正则表达式进行提取字符串里面的数字: public class MyTest { public static void main(String[] args) throws Exception { List prods = new ArrayList (); prods.add("5斤"); prods.add("15袋"); String p = null; for (int i = 0; i < prods.size(); i++) { p = prods.get(i); String str ...
  • Java子串接受值0到variable.length (包括)。 给定的数字不是指字符的位置,而是指字符之间的点的位置。 例如: 0 :a: 1 :p: 2 :p: 3 :l: 4 :e: 5 5返回一个空字符串,因为之后没有字符。 6抛出异常,因为没有第六个位置。 The Java substring accepts values 0 through variable.length (inclusive). The number given refers not to the location of a ...
  • 当你在Java中分配任何东西,在这种情况下是一个String ,只要你仍然有办法访问它,它就会保留在内存中。 如果你写 String s = "blah"; 然后s是对该String的引用 。 只要至少有一个对String引用,那么JVM就知道它需要在内存中保留。 一旦没有更多引用,JVM就可以清理它并在需要时回收内存。 如果你写 String s = "myverylongstring...somemore...someotherstuff"; 然后你耗尽了相当多的记忆。 在内部,这将表示为包含Str ...
  • 就像@danben说的那样,你需要发布错误以获得有意义的帮助。 但是,看看你的代码,我想象错误时的duedate为null 。 您可能需要在while循环中移动实际使用 duedate的代码。 Like @danben says, you need to post the error to get meaningful help. Looking at your code, though, I'd imagine that duedate at the time of the error is null. ...
  • 要使用Java获取给定String所有子String ,可以使用此GetSubtrings方法: public static ArrayList GetSubstrings(String str) { // set up any substring and add it to the ArrayList ArrayList subStrings = new ArrayList(); for (int i = 0; i < str.length(); ...
  • String untrimmed = " some string "; String trimmed = ""; String innerSpaces = ""; boolean wordBoundary = true; try { for (int i = 0; ; i++) { String substr = untrimmed.substring(i, i + 1); if (!substr.equals(" ") && !substr.equa ...
  • 没有泄漏。 请注意,您正在创建大量的String对象。 如果一个String的长度为1000个字符,那么您将创建1000个对象。 真的需要创建这么多的String对象吗? 例如可以使用char[]来达到你想要的效果吗? There is no leak. Please note that you're creating a huge amount of String objects. If a String has a length of 1000 characters you're creating 10 ...
  • 正如您链接的文章中所解释的那样,这两种方法之间的唯一区别是返回类型。 一个返回一个String ,另一个返回一个CharSequence 。 要理解的是CharSequence是一个接口 , String是一个实现 CharSequence的类 。 所以每个String也是CharSequence ,但反之亦然。 您可以将substring()的输出分配给CharSequence类型的变量,但不是相反: String string = "Hello"; String subString1 = string ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)