java.text.ParsePosition類的setErrorIndex()方法用於設置可能發生解析錯誤的索引。
用法:
public void setErrorIndex(int ei)
參數:此方法將整數ei作為參數,可能會發生解析錯誤。
返回值:此方法無返回值。
下麵是說明setErrorIndex()方法的示例:
範例1:
// Java program to demonstrate
// setErrorIndex() method
import java.text.*;
import java.util.*;
import java.io.*;
public class GFG {
public static void main(String[] argv)
{
try {
// Creating and initializing
// new ParsePosition Object
ParsePosition pos
= new ParsePosition(1);
// set index for the parsing error
// using setErrorIndex() method
pos.setErrorIndex(3);
// getting the current
// ParsePosition of
int i = pos.getErrorIndex();
// display result
System.out.println(
"index at which error occurred:"
+ Integer.toString(i));
}
catch (ClassCastException e) {
System.out.println(e);
}
}
}
輸出:
index at which error occurred:3
範例2:
// Java program to demonstrate
// setErrorIndex() method
import java.text.*;
import java.util.*;
import java.io.*;
public class GFG {
public static void main(String[] argv)
{
try {
// Creating and initializing
// new ParsePosition Object
ParsePosition pos
= new ParsePosition(500);
// set index for the parsing error
// using setErrorIndex() method
pos.setErrorIndex(3000);
// getting the current
// ParsePosition of
int i = pos.getErrorIndex();
// display result
System.out.println(
"index at which error occurred:"
+ Integer.toString(i));
}
catch (ClassCastException e) {
System.out.println(e);
}
}
}
輸出:
index at which error occurred:3000
參考: https://docs.oracle.com/javase/9/docs/api/java/text/ParsePosition.html#setErrorIndex-int-
相關用法
- Java ParsePosition getErrorIndex()用法及代碼示例
- Java ParsePosition getIndex()用法及代碼示例
- Java ParsePosition equals()用法及代碼示例
- Java ParsePosition toString()用法及代碼示例
- Java ParsePosition hashCode()用法及代碼示例
- Java ParsePosition setIndex()用法及代碼示例
- Java DateFormat parse(string , ParsePosition)用法及代碼示例
- Java Java lang.Long.builtcount()用法及代碼示例
- Java Java lang.Long.numberOfLeadingZeros()用法及代碼示例
- Java Java lang.Long.highestOneBit()用法及代碼示例
- Java Java lang.Long.byteValue()用法及代碼示例
- Java Java lang.Long.reverse()用法及代碼示例
- Java Java.util.Collections.disjoint()用法及代碼示例
- Java Java.util.Collections.rotate()用法及代碼示例
注:本文由純淨天空篩選整理自RohitPrasad3大神的英文原創作品 ParsePosition setErrorIndex() method in Java with Example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。