欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

java-制表符\t的使用說明

 更新時間:2021年02月26日 08:39:04   作者:龜?shù)男√? 
這篇文章主要介紹了java-制表符\t的使用說明,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

1.用法

\t 表示制表符,相當于制表符

前面的輸出內(nèi)容位數(shù)為8的倍數(shù),\t將輸出8個空格

前面的輸出內(nèi)容位數(shù)不是8的倍數(shù),\t將補足8位

2.測試用例

少于8位

等于8位

大于8位

3.代碼測試

以下為相關代碼測試:

package mypro01;
/*
 * \t測試
 * \t 制表符,相當于8個空格;前面的輸出內(nèi)容位數(shù)是8的倍數(shù),輸出8個空格;不足8位,補足8位。
 */
public class Test {
 public static void main(String[] args) {
 System.out.println("123456\t前面內(nèi)容有6位,補2個空格");
 System.out.println("12345678\t前面內(nèi)容有8位,加8個空格");
 System.out.println("123456789012345\t前面內(nèi)容有15位,補1個空格");
 }
}

4.運行結(jié)果

補充:java如何把String字符串中所有的空格和制表符(\t)替換成單個符號。

該方法可用于將字符串分解成若干有用的數(shù)組。

大致代碼如下:

package test;
import java.util.ArrayList;
import java.util.List;
/**
 * @author : suyuyuan
 * @date :2016年5月18日 上午11:28:47
 * @version 1.0
 */
public class a {
public static void main(String[] args) {
String s="qw er as";  //字符串s中包含若干空格和制表符 \t。
String newstr1=s.replaceAll(" ",","); //先把所有空格替換成 逗號。
System.out.println(newstr1);
String newstr2=newstr1.replaceAll("\t",","); //再把所有的制表符替換成逗號。
System.out.println(newstr2);
String newstr3=newstr2.replaceAll(",+", ","); //把所有重復的逗號合并成一個逗號。
System.out.println(newstr3);
String[] strings=newstr3.split(",");  //按逗號分解該字符串。
List<String> stringList = new ArrayList<String>(); //將分解后的字符串數(shù)組存儲到ArrayList對象當中。
for(int i=0;i<strings.length;i++){
stringList.add(strings[i].trim());
}
System.out.println(stringList);
}
}

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。如有錯誤或未考慮完全的地方,望不吝賜教。

相關文章

最新評論